- 1

Beginner Python question.

Having some troubles with a question asking to fix a problem X = input() Print(x+10) I can seem to figure it out so any help would be awesome. Thank you!

25th Jan 2022, 5:03 AM
Dakota Rodriguez
Dakota Rodriguez - avatar
20 Antworten
+ 15
error 1: x variable needs to be lowercase when inputting x = input() not X = input() error 2: use * to multiply strings not + print(x * 10) error 3: print() should be lowercase not Print() resulting code should be : x = input() print(x * 10)
25th Jan 2022, 8:35 AM
Shen Bapiro
Shen Bapiro - avatar
+ 5
Do this x = int(input ()) print (x+10)
25th Jan 2022, 1:08 PM
Hamza Yousfi
Hamza Yousfi - avatar
+ 4
You're trying to add values of different types. That's not possible.
25th Jan 2022, 5:06 AM
Simon Sauter
Simon Sauter - avatar
+ 2
Hey as far as i know, input() takes i/p as a string. That means you can't add a string(X in your case) with an integer. Now let X = 5 and if you want o/p to be 10 times i.e. 50 Then just caste your string in to integer You can do like this... print(int(X)*10) #50 OR if you do print(X*10) #5555555555 also another approach is to get user input as X = int(input())
25th Jan 2022, 5:58 AM
saurabh
saurabh - avatar
0
Input returns a string value to output it 10 times just replace '+' by '*'. '+' is used for concatenation of string or simple additions of integer. Here since you have 2 different data types you will get error
25th Jan 2022, 6:20 AM
Sanjyot21
Sanjyot21 - avatar
0
X is not x 🙃 Python is case sensitive
25th Jan 2022, 1:06 PM
Hamza Yousfi
Hamza Yousfi - avatar
0
Print is not print Again python is case sensitive
25th Jan 2022, 1:07 PM
Hamza Yousfi
Hamza Yousfi - avatar
0
Python is sensitive here,X and x are different so you correct your variable.
26th Jan 2022, 6:44 AM
SK SANOWAR
0
The value you get from the input() function is considered as string by default. And, use of + in print concatenates(adds 1 string at the end of another) the data in ( ) of the print command. Now, Python is case sensitive, meaning X and x are considered as 2 different variables. So, you will have to decide on using either and stick to it. In the code you have mentioned here, this is what happens, - you get an error because x is undefined (keeping in mind you have initialized X and not x) -(let's say we have X in print, after being initialized to an input value) since the value in X is considered string by default, you will obtain:- X10 (here X is any value you have given as input, be it "hi" or any integer say 45, like hi10 or 4510 is your output ) -if your intention was to take an integer input and add 10 to it, you will have to use this type conversion (casting) - X = int(input()) This way you will be able to add 10 to X later Hope this helps, feel free to ask queries if any :)
26th Jan 2022, 5:18 PM
Shreya Iyengar
0
While getting the input, it would be in string format, use the formatter function to convert into integer. Ex, Print(int(x)+10) This would work for sure.
26th Jan 2022, 10:45 PM
Sudhakaran K
0
print(10+int(input()))
30th Jan 2022, 11:55 AM
Hamza Yousfi
Hamza Yousfi - avatar
- 1
So the answer was to switch the + with a * Im not sure how I didnt catch that. They want the output to be 10 times
25th Jan 2022, 5:26 AM
Dakota Rodriguez
Dakota Rodriguez - avatar
- 1
x = int(input('enter:')) print(x +100)
25th Jan 2022, 7:14 AM
Saad Khan
Saad Khan - avatar
- 1
Value of x is string. You can't add value to a string. So you should convert input type as string. x = int(input())
25th Jan 2022, 2:02 PM
Dhanush J.A
Dhanush J.A - avatar
- 1
You are adding a string and Integer datatype which is a big flaw..
26th Jan 2022, 12:22 PM
Jyothiswarup Seethala
Jyothiswarup Seethala - avatar
- 1
here, X is in capital.
26th Jan 2022, 1:15 PM
Om Sachin Wagh
Om Sachin Wagh - avatar
- 1
The problem here is that if you enter a string it will show you an error and also no Print, the command is print() declare and accept the same data type, either with upper Or lower case
26th Jan 2022, 3:43 PM
Arman Alli
Arman Alli - avatar
- 1
And let me clarify another scenario, if in case you wanted the value in X to be displayed 10 times, you will have to use this - X = input() print (X*10) This way your input, whether an integer or a string, will be displayed 10 times consecutively.
26th Jan 2022, 5:21 PM
Shreya Iyengar
- 1
The problem refers to concatenation such as input function takes string value that can't be concatenated with integer value. I hope it'll help
26th Jan 2022, 5:38 PM
Rajat Kumar
- 4
X=output
25th Jan 2022, 8:14 PM
Juliet Ifeoma