Skip to content

Update 5.1.7 Divisibility.py - Incorrect Answer #1

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

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
26 changes: 10 additions & 16 deletions CodeHs/3.Looping/1. While Loops/5.1.7 Divisibility.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
numerator = int(input("Enter a numerator: "))
denominator = 0 # Initialize the denominator with 0

while(True):
denominator = int(input("Enter denominator: "))
if(denominator!=0):
break
else:
continue
# Keep asking for the denominator until it's not zero
while denominator == 0:
denominator = int(input("Enter denominator (non-zero): "))
if denominator == 0:
print("Denominator cannot be zero. Please enter a non-zero value.")

# Use a while loop here to repeatedly ask the user for
# a denominator for as long as the denominator is 0
# (or, put another way, until the denominator is not
# equal to 0).



if numerator / denominator * denominator == numerator:
print "Divides evenly!"
# Check if the division is even
if numerator % denominator == 0:
print("Divides evenly!")
else:
print "Doesn't divide evenly."
print("Doesn't divide evenly.")