0

Hello,I'm on the exercise of working with input, someone can tell me why this is not accepted? x=str("hi") y=int(3) print(x*y)

Working with input

19th Oct 2022, 11:50 AM
Marco Grotto
Marco Grotto - avatar
60 Réponses
+ 8
Is the exercise named "Working with input"? Possibly you need to use the input() statement to read one or more of the values. Take note: "hi" is already a string. The quotation marks define it as a string. It is redundant to convert it to string with the str("hi") function. Likewise, 3 is already an int, since it does not have quotation marks, so y = 3 is enough.Though, if y is taken as input then the input will need to be converted to int. That is because input() returns a string. It would look like this: y = int(input())
19th Oct 2022, 1:12 PM
Brian
Brian - avatar
+ 6
Marco Grotto hard coding is you are giving value to variable.. instead of getting it as user input
20th Oct 2022, 8:06 AM
Riya
Riya - avatar
20th Oct 2022, 7:51 AM
Avinash
Avinash - avatar
+ 3
Hello, you should just write x="hi" Or if you wanna something different write x=input() so then you can work with a string ✨ Also you should write y=3 Or if you wanna something different write y=int(input()) so then you can work with a integer number ✨
21st Oct 2022, 3:46 AM
Murrr
19th Oct 2022, 12:10 PM
Riya
Riya - avatar
+ 2
What error message it is showing can you clarify?
19th Oct 2022, 5:43 PM
Riya
Riya - avatar
+ 2
Marco Grotto is either of one case only passed for you?
19th Oct 2022, 5:49 PM
Riya
Riya - avatar
+ 2
Try this way: x = input() y = input() print(x*int(y))
19th Oct 2022, 9:28 PM
Patryk Skonieczny
Patryk Skonieczny - avatar
+ 2
x=input () y=int(input()) print(x*y) This is working fine in pc . May be in solo learn it's not allowed to input more than one input. in this code you have to first input string which you want multiple times and then input how many times do you want to print that string.
20th Oct 2022, 1:45 AM
Avinash
Avinash - avatar
+ 2
Marco Grotto from your question you post, First input should be a string Second should be integer So, A=input() B=int(input()) Print (A*B) It will work...
20th Oct 2022, 7:58 AM
Riya
Riya - avatar
+ 2
Michael Wambua how string can print any string multiple times?
20th Oct 2022, 8:03 AM
Avinash
Avinash - avatar
+ 2
Avinash Kumar thanks that finally work, but what is hard coding?
20th Oct 2022, 8:04 AM
Marco Grotto
Marco Grotto - avatar
+ 2
Marco Grotto hard coding means you already take variable value just like x="hi" and y=2 or any number. But in soft coding user gives value through input function
20th Oct 2022, 8:07 AM
Avinash
Avinash - avatar
+ 2
Okok thanks, now I get it
20th Oct 2022, 8:08 AM
Marco Grotto
Marco Grotto - avatar
+ 1
Marco Grotto it is accepted only run the code and see...it's working it prints hi 3 times
19th Oct 2022, 12:05 PM
Riya
Riya - avatar
+ 1
Then don't declare the input yourself...get it as user input
19th Oct 2022, 5:34 PM
Riya
Riya - avatar
+ 1
x=str(input()) y=int(input()) print(x*y) like this
19th Oct 2022, 5:36 PM
Riya
Riya - avatar
+ 1
It's quite hard may be there is mistake in question
19th Oct 2022, 6:00 PM
Riya
Riya - avatar
+ 1
Marco Grotto can you screenshot the question and post it here..may be you missed something in it
20th Oct 2022, 6:22 AM
Riya
Riya - avatar
+ 1
Riya your code is showing error in this platform
20th Oct 2022, 7:05 AM
Avinash
Avinash - avatar