+ 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")

14th Dec 2024, 12:37 PM
Ella
Ella - avatar
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 😊
14th Dec 2024, 12:56 PM
ミ★ 𝘕𝘉 ★彡
ミ★ 𝘕𝘉 ★彡 - avatar
+ 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')
14th Dec 2024, 8:22 PM
Lothar
Lothar - avatar
+ 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]
15th Dec 2024, 7:03 PM
Lothar
Lothar - avatar
+ 1
Write name to "name" The Code will run
15th Dec 2024, 1:21 PM
Rahul Melkani
Rahul Melkani - avatar
0
no name variable?
15th Dec 2024, 1:24 PM
Kunal Rana
Kunal Rana - avatar
0
name=input() age=int(input()) if age>=18: print(name+”is”+str(age)+”years old”) …
15th Dec 2024, 6:02 PM
Pavel Kozlov
0
whar issues html
15th Dec 2024, 9:05 PM
Muka Nekir
Muka Nekir - avatar