science facts and news

Thursday, July 22, 2021

Python guessing the number!

 import math

import random

correct_number = random.randint(120)
print(correct_number)
guess_counter = 0
guess_limit = 3
user_guess = 0

while guess_counter < guess_limit and correct_number != user_guess:
    user_guess = int(input('Enter a number (1-20): '))
    guess_counter += 1
    if user_guess == correct_number:
        print("Great! That's correct")
    elif user_guess < correct_number:
        print('less! increase the value')
    elif user_guess > correct_number:
        print('High! decrease the value')

    else:
        print('Sorry! out of guesses!')

Monday, July 5, 2021

Given n, take the sum of the digits of n and continue until it reaches to single-digit - Codewars solution(Python)

def digital_root(n):
    x = sum(int(ifor i in str(n))
    if x > 9:
        return digital_root(x)
    return x


print(digital_root(2333))
Python program to return first non-repeating letter - Codewars solution.

def first_non_repeating_letter(string):
    low_str = []
    for i in string:
        low_str.append(i.lower())
    for i in string:
        if low_str.count(i.lower()) == 1:
            return i
    return ''


print(first_non_repeating_letter('sTreSS'))

About Me

Kohalpur, Banke, Nepal
Hi, I'm Roshan , a student just trying to explore the world of programming