- 1
Asking for 2 numbers
program that ask for 2 numbers, how do I go about that
6 Answers
+ 5
In code playground, you must give all entries required by your script at once, just when it begins ( each separated by new line )...
However, if you mean ask for 2 numbers at once input() call, you need split the returned string by a specific character ( "1 2" or "1,2" and so on )
Anyway, as input() returned value is always of type string, you have to cast it to number type ( int or float )
numstr = "42"
numfloat = float(numstr)
numint = int(numstr)
... by the way, you can define a function to auto cast string to mosr better suited number type:
def number(n):
try:
if '.' in n:
return float(n)
else:
return int(n)
except:
return None
num = number("42")
+ 4
num_1 = int(input())
num_2 = int(input())
if (num_1 + num_2) > 100:
print("etc.")
# If you are in the code playground you have to enter the two numbers each in its line to avoid and EOFError.
EDITED:
converted the input to int. This is just a demo though.
+ 3
If you are doing your code in the code playground, run this code to see a possible cause and how to handle it:
https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
+ 1
@Ulisses: input() returns a string.
0
I'm still running into errors, I'm not sure what I'm doing
0
what I'm suppose to do is write a program that asked for 2 numbers. and if the sum of the two numbers is greater than 100 it prints "etc."