Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 9_for_exercise.py #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Basics/Exercise/9_for/9_for_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@
print("Hurray! You are a rock star! You just finished 5 km race!")
else:
print("You didn't finish 5 km race but hey congrats anyways! You still ran {i+1} miles")
#I wanted to only take two valid inputs. Either "yes" or "no"(case-insensitive). That's why I tried the code below:
for i in range(1,6):
while True:
yorn = input(f"You ran {i} miles. Are you tired? ")
if yorn.lower() == "yes":
if i<5:
print(f"you didn't finish the race but still ran {i} miles")
else:
print(f"Congratulations! You have finished the race by running {i} miles.")
break
elif yorn.lower() == "no":
break
else:
print("Invalid input! Please enter either 'yes' or 'no'.")
if yorn.lower() == "yes":
break
else:
print(f"congratulations!!! You have finished the race by running {i} miles.")

# 5. Write a program that prints following shape
# ```
Expand All @@ -77,4 +95,4 @@
s = ''
for j in range(i):
s += '*'
print(s)
print(s)