why cant i do this in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

why cant i do this in python?

why cant i do this: ans = input(name, "whats the answer: ")

14th Jun 2019, 11:36 AM
Cat Sauce
Cat Sauce - avatar
7 Answers
+ 3
~ swim ~ it prints: cat whats the answer: and asks for the answrr
14th Jun 2019, 11:52 AM
Cat Sauce
Cat Sauce - avatar
+ 3
I think u can use string formatting If name is a variable where u store name then u can try this ans=input("{},whats the answer:".format(name))
14th Jun 2019, 12:02 PM
Nandini
+ 3
Run help(input) and help(print) and compare what you get. input() expects one parameter (prompt) which can be None. You can't provide more arguments than the method accepts
14th Jun 2019, 12:30 PM
Anna
Anna - avatar
+ 3
Format your strings, input only accepts 1 parameter ans = input(f"{name} whats the answer")
15th Jun 2019, 12:02 AM
Choe
Choe - avatar
+ 2
~ swim ~ as input also prints a value, it would make sense, that it would output text like print function.
14th Jun 2019, 12:13 PM
Seb TheS
Seb TheS - avatar
+ 1
The current value of name variable will be stored in placeholder {}
14th Jun 2019, 12:04 PM
Nandini
0
name= "mi nombre"; print nombre;
17th Jun 2019, 2:24 PM
jhordan loaisiga flores
jhordan loaisiga flores - avatar