Python Forum
a little help with a While Loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a little help with a While Loop
#1
A newbie here Big Grin

This code prints "too many tires" at every loop.
The goal is to print it at the end of the loop only. (after 3 wrong tries)
Can someone help ?

x = 1 while x <= 3: name = input("Enter your username: ") if len(name) < 5: print(f"{name} is too short") elif len(name) > 9: print (f"{name} is too long") else: print(f"Welcome {name} !") break x += 1 print("too many tries !")
Reply
#2
I figured it

x = 1 while x <= 3: name = input("Enter your username: ") if len(name) < 5: print(f"{name} is too short") elif len(name) > 9: print (f"{name} is too long") else: print(f"Welcome {name} !") break x += 1 else: print("too many tries !")
Reply
#3
(Feb-07-2020, 04:25 PM)Hob_78 Wrote: I figured it

x = 1 while x <= 3: name = input("Enter your username: ") if len(name) < 5: print(f"{name} is too short") elif len(name) > 9: print (f"{name} is too long") else: print(f"Welcome {name} !") break x += 1 else: print("too many tries !")
if i give a name which is having length of 7, it is printing welcome msg why ???
Reply


User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.