age calculator exercise completed
This commit is contained in:
parent
7b30662605
commit
9c2b04b11e
19
age_calc.py
Normal file
19
age_calc.py
Normal file
@ -0,0 +1,19 @@
|
||||
while True:
|
||||
try:
|
||||
age = input("Enter your age: ")
|
||||
if int(age) > 0 and int(age) < 13:
|
||||
print("You're a kid!")
|
||||
elif int(age) >= 13 and int(age) <= 19:
|
||||
print("You're a teenager!")
|
||||
elif int(age) >= 20 and int(age) <= 64:
|
||||
print("You're an adult!")
|
||||
elif int(age) >= 65 and int(age) <= 160:
|
||||
print("You're a senior!")
|
||||
elif int(age) > 160:
|
||||
print("C'mon bruv, you should be ded by now.")
|
||||
except ValueError:
|
||||
print("Invalid input, please try again.")
|
||||
except Exception as e:
|
||||
print("Try again!")
|
||||
|
||||
|
||||
27
guessNum.py
Normal file
27
guessNum.py
Normal file
@ -0,0 +1,27 @@
|
||||
import random
|
||||
|
||||
generated_num = random.randint(1, 100)
|
||||
|
||||
|
||||
def get_Num():
|
||||
return input("Guess the number between 1 and 100: ")
|
||||
|
||||
|
||||
numbers_guessed = []
|
||||
tries = 0
|
||||
|
||||
while True:
|
||||
guess = get_Num()
|
||||
if int(guess) == generated_num:
|
||||
print(f"Correct! You guessed the number in {tries} tries.")
|
||||
break
|
||||
elif int(guess) != generated_num:
|
||||
tries += 1
|
||||
if int(guess) in numbers_guessed:
|
||||
print(f"Already tried {guess}.")
|
||||
continue
|
||||
elif int(guess) < generated_num:
|
||||
print("Too low")
|
||||
elif int(guess) > generated_num:
|
||||
print("Too high")
|
||||
numbers_guessed.append(int(guess))
|
||||
Loading…
x
Reference in New Issue
Block a user