Jump to content

hi

 

im trying things with python using While and get a problem when i run this code.

test = input("Enter a number: ")char = test.isalpha()while char == True:        print("Sorry that contains letters")        test = ("Enter a number again: ")

what happens is it constantly prints "Sorry that contains letters" and doesn't move on-to the next line of code. what am i doing wrong

 

thanks

Link to comment
https://linustechtips.com/topic/53836-python-while/
Share on other sites

Link to post
Share on other sites

oh thanks

Edit.... nevermind, didn't see that you were using 3.* my brain is a bit fried 

Intel 3570K - MSI GTX 660Ti 3GB OC Edition - 16GB Corsair LP RAM - ASRock Extreme4 Motherboard - Corsair HX850 - Adata Premier Pro SP900 120GB SSD with Windows 7 - Seagate Barracuda 1TD HDD - Seagate Barracuda 500GB HDD - Thermaltake Frio CPU Cooler - CM Storm Enforcer Case - Macbook Pro Early 2011 Laptop

Link to comment
https://linustechtips.com/topic/53836-python-while/#findComment-722927
Share on other sites

Link to post
Share on other sites

Dunno if it'll still work, making the above change. You're not testing for isalpha again after the second input.

test = input("Enter a number: ")while test.isalpha() == True:       print("Sorry that contains letters")       test = input("Enter a number again: ")

May also need a break condition.

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
https://linustechtips.com/topic/53836-python-while/#findComment-722944
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×