- 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!
20 Respostas
+ 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)
+ 5
Do this
x = int(input ())
print (x+10)
+ 4
You're trying to add values of different types. That's not possible.
+ 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())
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
0
X is not x š
Python is case sensitive
0
Print is not print
Again python is case sensitive
0
Python is sensitive here,X and x are different so you correct your variable.
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 :)
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.
0
print(10+int(input()))
- 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
- 1
x = int(input('enter:'))
print(x +100)
- 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())
- 1
You are adding a string and Integer datatype which is a big flaw..
- 1
here, X is in capital.
- 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
- 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.
- 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
- 4
X=output