print("kaivan shah")
print ("HI!")
age = "12"
if age is (">12"):
print("you cannot drink beer")
if age is ("=12"):
print("you cann drink beer")
if age is ("<=20"):
print("extra beer!")
print("happy journey!")
it is not printing the values
In your code there might be type error
and there is no proper if condition have checked i guess
Are you sure if age is (">12"):
is a valid comparison?
Should it not be if int(age) > 12:
?
And why is the variable “age” a string in the first place?
Hi @shah-kaivan the solution is below:
# Make sure that you use an integer for the number 12 instead of a string
age = 12
# Your "if" expressions aren't written correctly
if age > 12:
print("you can't drink beer")
if age == 12:
print("You can drink beer!")
if age <= 20:
print("You get an extra beer!")
print ("HI!")
age = "12"
if age < "12":
print("you cannot drink beer")
if age == "12":
print("you cann drink beer")
if age >= "20":
print("extra beer!")
print("happy journey!")```
use “;”
at the end of every phrase or statement
I am an old man 68 trying to venture in to the youth domain by trying to learn Python. Can anyone guide me on coding the following:
#computer asks user to select a number between 1 and 10.
#user selects a random number.
computer guesses a lower than selected number.
user asks him to guess higher.
computer guesses a higher than selected number.
user asks him to guess lower.
computer guesses a correct number.
user congratulates him.
Hello Karim,
This task should be placed outside this curriculum topic i believe.
I might advice to look into python range() method and random() method.
Range can be used to pick a number from a range of numbers, random can be used to generate random number (also between a certain range).
Both seem to me to be useful in this assignment.
Also classic If…else conditional statements.
import random
class GuessMyNumber:
def __init__(self):
self.cpu_number = random.randint(1,11)
def start(self):
ready = str.lower(input('Guess a number in your head between 1 and 10. Ready? [y, n]: '))
while ready in ['y', 'yes', 'ya', 'yup']:
reply = input('Is your number {}? [y, n]: '.format(self.cpu_number))
if reply == 'y':
print('Congrats! The computer figured out my number!')
break
else:
direction = str.lower(input('Is it higher or lower: '))
if direction == 'higher':
self.cpu_number += 1
else:
self.cpu_number -= 1
guess_my_number = GuessMyNumber()
guess_my_number.start()