Python - TypeError: can't multiply sequence by non-int of type 'str'
up vote
0
down vote
favorite
This is my code for a school project (I am writing this in Python 2.7.13):
def euconverter(mon, rate):
return (mon * rate)
cur = raw_input('Please give me the currency')
mon = raw_input('Please give me the value')
rate = raw_input('Please give me the rate')
while cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
else:
if cur != 'EUR' or cur != 'Eur' or cur != 'GBP' or cur != 'Gbp':
print 'Wrong input'
break
I get this error:
Traceback (most recent call last):
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 15, in <module>
print (euconverter(mon, rate))
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 2, in euconverter
return int(mon * rate)
TypeError: can't multiply sequence by non-int of type 'str'
Also, if I type a numeric value when it is asking me for the currency type, then the program exits without displaying any messages.
This is a school project, so I am expecting to get wrong inputs from the users and need to provide them with the required error message while trying to make them go back and input the correct one.
python python-2.7
|
show 5 more comments
up vote
0
down vote
favorite
This is my code for a school project (I am writing this in Python 2.7.13):
def euconverter(mon, rate):
return (mon * rate)
cur = raw_input('Please give me the currency')
mon = raw_input('Please give me the value')
rate = raw_input('Please give me the rate')
while cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
else:
if cur != 'EUR' or cur != 'Eur' or cur != 'GBP' or cur != 'Gbp':
print 'Wrong input'
break
I get this error:
Traceback (most recent call last):
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 15, in <module>
print (euconverter(mon, rate))
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 2, in euconverter
return int(mon * rate)
TypeError: can't multiply sequence by non-int of type 'str'
Also, if I type a numeric value when it is asking me for the currency type, then the program exits without displaying any messages.
This is a school project, so I am expecting to get wrong inputs from the users and need to provide them with the required error message while trying to make them go back and input the correct one.
python python-2.7
1
monandrateare strings. You need to convert them to numbers.
– khelwood
Nov 9 at 9:02
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Also yourwhileis an infinite loop, because you don't read a new value forcurinside it.
– khelwood
Nov 9 at 9:05
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my code for a school project (I am writing this in Python 2.7.13):
def euconverter(mon, rate):
return (mon * rate)
cur = raw_input('Please give me the currency')
mon = raw_input('Please give me the value')
rate = raw_input('Please give me the rate')
while cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
else:
if cur != 'EUR' or cur != 'Eur' or cur != 'GBP' or cur != 'Gbp':
print 'Wrong input'
break
I get this error:
Traceback (most recent call last):
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 15, in <module>
print (euconverter(mon, rate))
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 2, in euconverter
return int(mon * rate)
TypeError: can't multiply sequence by non-int of type 'str'
Also, if I type a numeric value when it is asking me for the currency type, then the program exits without displaying any messages.
This is a school project, so I am expecting to get wrong inputs from the users and need to provide them with the required error message while trying to make them go back and input the correct one.
python python-2.7
This is my code for a school project (I am writing this in Python 2.7.13):
def euconverter(mon, rate):
return (mon * rate)
cur = raw_input('Please give me the currency')
mon = raw_input('Please give me the value')
rate = raw_input('Please give me the rate')
while cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
else:
if cur != 'EUR' or cur != 'Eur' or cur != 'GBP' or cur != 'Gbp':
print 'Wrong input'
break
I get this error:
Traceback (most recent call last):
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 15, in <module>
print (euconverter(mon, rate))
File "C:/Users/Maple/PycharmProjects/untitled/Mid term Project.py", line 2, in euconverter
return int(mon * rate)
TypeError: can't multiply sequence by non-int of type 'str'
Also, if I type a numeric value when it is asking me for the currency type, then the program exits without displaying any messages.
This is a school project, so I am expecting to get wrong inputs from the users and need to provide them with the required error message while trying to make them go back and input the correct one.
python python-2.7
python python-2.7
edited Nov 9 at 9:53
Ralf
4,4164833
4,4164833
asked Nov 9 at 9:00
Maple Sapling
1
1
1
monandrateare strings. You need to convert them to numbers.
– khelwood
Nov 9 at 9:02
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Also yourwhileis an infinite loop, because you don't read a new value forcurinside it.
– khelwood
Nov 9 at 9:05
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08
|
show 5 more comments
1
monandrateare strings. You need to convert them to numbers.
– khelwood
Nov 9 at 9:02
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Also yourwhileis an infinite loop, because you don't read a new value forcurinside it.
– khelwood
Nov 9 at 9:05
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08
1
1
mon and rate are strings. You need to convert them to numbers.– khelwood
Nov 9 at 9:02
mon and rate are strings. You need to convert them to numbers.– khelwood
Nov 9 at 9:02
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Also your
while is an infinite loop, because you don't read a new value for cur inside it.– khelwood
Nov 9 at 9:05
Also your
while is an infinite loop, because you don't read a new value for cur inside it.– khelwood
Nov 9 at 9:05
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08
|
show 5 more comments
4 Answers
4
active
oldest
votes
up vote
0
down vote
As mentioned in comments, mon and raw are implicitly strings.
To convert them, use e.g. mon = int(mon) or mon = float(mon).
Be careful tho, as you should take care of invalid input (try - except TypeError block).
Few tips:
- Last if should use and instead of or
- there is no difference between these two lines:
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
you can group them together, if this is intentional
add a comment |
up vote
0
down vote
Some refactored code for your text input would look like:
legal_input = ["gbp", "eur", "yen"]
currency = raw_input("Please enter the currency type")
if currency.lower() in legal_input:
#some code to do the required operations
else:
print('not a recognised currency type!')
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
add a comment |
up vote
0
down vote
It seems that what you are trying to do is to prompt the user for input and validate it, and then ask again if it is not valid.
You can try that by wrapping each raw_input() inside a while-loop with a flag.
To validate the currency it would be easier to cast the input to uppercase and then check agains a list of allowed possibilities.
To validate the amount and rate, you could cast them to float inside a try-except block.
valid_currencies = ['EUR', 'GBP']
cur = None
mon = None
rate = None
is_valid = False
while not is_valid:
cur = raw_input('Please give me the currency').upper()
if cur in valid_currencies:
is_valid = True
else:
print 'Not a valid currency'
is_valid = False
while not is_valid:
try:
mon = float(raw_input('Please give me the value'))
is_valid = True
except ValueError:
print 'Not a valid value'
is_valid = False
while not is_valid:
try:
rate = float(raw_input('Please give me the rate'))
is_valid = True
except ValueError:
print 'Not a valid rate'
print 'Converted amount'
print mon * rate
add a comment |
up vote
0
down vote
def euconverter(mon, rate):
return mon * rate
cur = raw_input('Please give me the currency type ')
mon = float(raw_input('Please give me the ammount of money '))
rate = float(raw_input('Please give me the rate of the exchange '))
while True:
#i dont know how to make the false statement ending the program as well not necessary i think
if cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'EUR' or cur == 'Eur':
print (euconverter(mon, rate))
break
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
break
# I dont know if multiple breaks should be included here
else:
print 'wrong input'
cur = raw_input('Please give me the currency type again correcntly this time ')
continue
With tips and help from everyone i finally got it running prompting the user to enter an other currency in the currency input line when wrong appreciate your help you'll be hearing from me soon again xD
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
As mentioned in comments, mon and raw are implicitly strings.
To convert them, use e.g. mon = int(mon) or mon = float(mon).
Be careful tho, as you should take care of invalid input (try - except TypeError block).
Few tips:
- Last if should use and instead of or
- there is no difference between these two lines:
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
you can group them together, if this is intentional
add a comment |
up vote
0
down vote
As mentioned in comments, mon and raw are implicitly strings.
To convert them, use e.g. mon = int(mon) or mon = float(mon).
Be careful tho, as you should take care of invalid input (try - except TypeError block).
Few tips:
- Last if should use and instead of or
- there is no difference between these two lines:
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
you can group them together, if this is intentional
add a comment |
up vote
0
down vote
up vote
0
down vote
As mentioned in comments, mon and raw are implicitly strings.
To convert them, use e.g. mon = int(mon) or mon = float(mon).
Be careful tho, as you should take care of invalid input (try - except TypeError block).
Few tips:
- Last if should use and instead of or
- there is no difference between these two lines:
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
you can group them together, if this is intentional
As mentioned in comments, mon and raw are implicitly strings.
To convert them, use e.g. mon = int(mon) or mon = float(mon).
Be careful tho, as you should take care of invalid input (try - except TypeError block).
Few tips:
- Last if should use and instead of or
- there is no difference between these two lines:
if cur == 'Eur' or cur == 'Eur':
print (euconverter(mon, rate))
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
you can group them together, if this is intentional
answered Nov 9 at 9:17
Michal Polovka
363414
363414
add a comment |
add a comment |
up vote
0
down vote
Some refactored code for your text input would look like:
legal_input = ["gbp", "eur", "yen"]
currency = raw_input("Please enter the currency type")
if currency.lower() in legal_input:
#some code to do the required operations
else:
print('not a recognised currency type!')
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
add a comment |
up vote
0
down vote
Some refactored code for your text input would look like:
legal_input = ["gbp", "eur", "yen"]
currency = raw_input("Please enter the currency type")
if currency.lower() in legal_input:
#some code to do the required operations
else:
print('not a recognised currency type!')
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
add a comment |
up vote
0
down vote
up vote
0
down vote
Some refactored code for your text input would look like:
legal_input = ["gbp", "eur", "yen"]
currency = raw_input("Please enter the currency type")
if currency.lower() in legal_input:
#some code to do the required operations
else:
print('not a recognised currency type!')
Some refactored code for your text input would look like:
legal_input = ["gbp", "eur", "yen"]
currency = raw_input("Please enter the currency type")
if currency.lower() in legal_input:
#some code to do the required operations
else:
print('not a recognised currency type!')
answered Nov 9 at 9:21
Scott Anderson
879
879
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
add a comment |
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
We aren't taught how to use legal input therefore i cannot add it to a project :/
– Maple Sapling
Nov 9 at 9:28
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
Ok well read my comment on the question as to why your while loop stops you from catching any input errors
– Scott Anderson
Nov 9 at 10:02
add a comment |
up vote
0
down vote
It seems that what you are trying to do is to prompt the user for input and validate it, and then ask again if it is not valid.
You can try that by wrapping each raw_input() inside a while-loop with a flag.
To validate the currency it would be easier to cast the input to uppercase and then check agains a list of allowed possibilities.
To validate the amount and rate, you could cast them to float inside a try-except block.
valid_currencies = ['EUR', 'GBP']
cur = None
mon = None
rate = None
is_valid = False
while not is_valid:
cur = raw_input('Please give me the currency').upper()
if cur in valid_currencies:
is_valid = True
else:
print 'Not a valid currency'
is_valid = False
while not is_valid:
try:
mon = float(raw_input('Please give me the value'))
is_valid = True
except ValueError:
print 'Not a valid value'
is_valid = False
while not is_valid:
try:
rate = float(raw_input('Please give me the rate'))
is_valid = True
except ValueError:
print 'Not a valid rate'
print 'Converted amount'
print mon * rate
add a comment |
up vote
0
down vote
It seems that what you are trying to do is to prompt the user for input and validate it, and then ask again if it is not valid.
You can try that by wrapping each raw_input() inside a while-loop with a flag.
To validate the currency it would be easier to cast the input to uppercase and then check agains a list of allowed possibilities.
To validate the amount and rate, you could cast them to float inside a try-except block.
valid_currencies = ['EUR', 'GBP']
cur = None
mon = None
rate = None
is_valid = False
while not is_valid:
cur = raw_input('Please give me the currency').upper()
if cur in valid_currencies:
is_valid = True
else:
print 'Not a valid currency'
is_valid = False
while not is_valid:
try:
mon = float(raw_input('Please give me the value'))
is_valid = True
except ValueError:
print 'Not a valid value'
is_valid = False
while not is_valid:
try:
rate = float(raw_input('Please give me the rate'))
is_valid = True
except ValueError:
print 'Not a valid rate'
print 'Converted amount'
print mon * rate
add a comment |
up vote
0
down vote
up vote
0
down vote
It seems that what you are trying to do is to prompt the user for input and validate it, and then ask again if it is not valid.
You can try that by wrapping each raw_input() inside a while-loop with a flag.
To validate the currency it would be easier to cast the input to uppercase and then check agains a list of allowed possibilities.
To validate the amount and rate, you could cast them to float inside a try-except block.
valid_currencies = ['EUR', 'GBP']
cur = None
mon = None
rate = None
is_valid = False
while not is_valid:
cur = raw_input('Please give me the currency').upper()
if cur in valid_currencies:
is_valid = True
else:
print 'Not a valid currency'
is_valid = False
while not is_valid:
try:
mon = float(raw_input('Please give me the value'))
is_valid = True
except ValueError:
print 'Not a valid value'
is_valid = False
while not is_valid:
try:
rate = float(raw_input('Please give me the rate'))
is_valid = True
except ValueError:
print 'Not a valid rate'
print 'Converted amount'
print mon * rate
It seems that what you are trying to do is to prompt the user for input and validate it, and then ask again if it is not valid.
You can try that by wrapping each raw_input() inside a while-loop with a flag.
To validate the currency it would be easier to cast the input to uppercase and then check agains a list of allowed possibilities.
To validate the amount and rate, you could cast them to float inside a try-except block.
valid_currencies = ['EUR', 'GBP']
cur = None
mon = None
rate = None
is_valid = False
while not is_valid:
cur = raw_input('Please give me the currency').upper()
if cur in valid_currencies:
is_valid = True
else:
print 'Not a valid currency'
is_valid = False
while not is_valid:
try:
mon = float(raw_input('Please give me the value'))
is_valid = True
except ValueError:
print 'Not a valid value'
is_valid = False
while not is_valid:
try:
rate = float(raw_input('Please give me the rate'))
is_valid = True
except ValueError:
print 'Not a valid rate'
print 'Converted amount'
print mon * rate
answered Nov 9 at 9:30
Ralf
4,4164833
4,4164833
add a comment |
add a comment |
up vote
0
down vote
def euconverter(mon, rate):
return mon * rate
cur = raw_input('Please give me the currency type ')
mon = float(raw_input('Please give me the ammount of money '))
rate = float(raw_input('Please give me the rate of the exchange '))
while True:
#i dont know how to make the false statement ending the program as well not necessary i think
if cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'EUR' or cur == 'Eur':
print (euconverter(mon, rate))
break
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
break
# I dont know if multiple breaks should be included here
else:
print 'wrong input'
cur = raw_input('Please give me the currency type again correcntly this time ')
continue
With tips and help from everyone i finally got it running prompting the user to enter an other currency in the currency input line when wrong appreciate your help you'll be hearing from me soon again xD
add a comment |
up vote
0
down vote
def euconverter(mon, rate):
return mon * rate
cur = raw_input('Please give me the currency type ')
mon = float(raw_input('Please give me the ammount of money '))
rate = float(raw_input('Please give me the rate of the exchange '))
while True:
#i dont know how to make the false statement ending the program as well not necessary i think
if cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'EUR' or cur == 'Eur':
print (euconverter(mon, rate))
break
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
break
# I dont know if multiple breaks should be included here
else:
print 'wrong input'
cur = raw_input('Please give me the currency type again correcntly this time ')
continue
With tips and help from everyone i finally got it running prompting the user to enter an other currency in the currency input line when wrong appreciate your help you'll be hearing from me soon again xD
add a comment |
up vote
0
down vote
up vote
0
down vote
def euconverter(mon, rate):
return mon * rate
cur = raw_input('Please give me the currency type ')
mon = float(raw_input('Please give me the ammount of money '))
rate = float(raw_input('Please give me the rate of the exchange '))
while True:
#i dont know how to make the false statement ending the program as well not necessary i think
if cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'EUR' or cur == 'Eur':
print (euconverter(mon, rate))
break
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
break
# I dont know if multiple breaks should be included here
else:
print 'wrong input'
cur = raw_input('Please give me the currency type again correcntly this time ')
continue
With tips and help from everyone i finally got it running prompting the user to enter an other currency in the currency input line when wrong appreciate your help you'll be hearing from me soon again xD
def euconverter(mon, rate):
return mon * rate
cur = raw_input('Please give me the currency type ')
mon = float(raw_input('Please give me the ammount of money '))
rate = float(raw_input('Please give me the rate of the exchange '))
while True:
#i dont know how to make the false statement ending the program as well not necessary i think
if cur == 'EUR' or cur == 'Eur' or cur == 'GBP' or cur == 'Gbp':
if cur == 'EUR' or cur == 'Eur':
print (euconverter(mon, rate))
break
elif cur == 'GBP' or cur == 'Gbp':
print (euconverter(mon, rate))
break
# I dont know if multiple breaks should be included here
else:
print 'wrong input'
cur = raw_input('Please give me the currency type again correcntly this time ')
continue
With tips and help from everyone i finally got it running prompting the user to enter an other currency in the currency input line when wrong appreciate your help you'll be hearing from me soon again xD
answered Nov 9 at 10:09
Maple Sapling
1
1
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222599%2fpython-typeerror-cant-multiply-sequence-by-non-int-of-type-str%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
monandrateare strings. You need to convert them to numbers.– khelwood
Nov 9 at 9:02
Possible duplicate of How do I do simple user input in python?
– khelwood
Nov 9 at 9:03
Also your
whileis an infinite loop, because you don't read a new value forcurinside it.– khelwood
Nov 9 at 9:05
@khelwood part of the answer is the same, yes but the question also asks about catching input errors
– Scott Anderson
Nov 9 at 9:06
@ScottAnderson Yes, but I can't also vote for "too broad".
– khelwood
Nov 9 at 9:08