+ 3
What's wrong with this code
name = input() age =int(input()) #input your age if age >= 18: print (name + " is " + age + " years old") elif age = 17: print ("one more year!") elif age = 16: print ("i cant give you a pass") else: print ("nice try")
7 odpowiedzi
+ 14
1. The variable "name" is used in the print statement but is not defined .
You could resolve the issue with inserting 👇 line at the top :
name=input() # Enter ur name
2. We use == for comparing values .The = is used for assignment and not comparision .
Replace = with == in elif statements
elif age==17:
elif age==16:
3. In the print statement you're trying to concatenate a string to an integer which is 'age' variable .
Convert 'age' to string using str(age)
like below:
print(name + "is" + str(age) + "years old")
Hope it helps 😊
+ 6
Ella ,
the print statement:
...
if age >= 18:
print (name + " is " + str(age) + " years old")
...
can also be done in a more simple way, with a better readability, performance, and the ability to handle various data types without using extra conversion. we can also avoid issues with additional or missing spaces in the output.
the arguments for output just needed to be separated by commas.
print(name, 'is', age, 'years old')
+ 2
Pavel Kozlov ,
> the quotes that are used are not correct, should be: " not ”.
> print output of the code will be: `tomis42years old`. as you can see, there are spaces missing.
to avoid this, i have recommended a more clear and simple way to use the arguments in the print() function.
[Program finished]
+ 1
Write name to "name"
The Code will run
0
no name variable?
0
name=input()
age=int(input())
if age>=18:
print(name+”is”+str(age)+”years old”)
…
0
whar issues html