Python Forum
WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP!
#8
[inline]

Hello deanhystad, thanks a bunchhh the code you suggested worked fine for all wrong inputs!!! Grateful.
Just learning Python, so getting my hands on writing codes related to real life problems.

[/inline]


def input_int(prompt):
    while True:
        try:
            inp = input(prompt)
            return int(inp)
        except ValueError as msg:
            print(msg)

dividend = input_int("Enter integer dividend: ")
while True:
    if divisor := input_int("Enter integer divisor: "):
        break
    print("Divisor cannot be zero.")    

def modulus(dividend):
    rem = dividend % divisor
    qout= dividend // divisor
    return (f"{dividend} modulo {divisor} has a remainder of {rem}")

print(modulus(dividend))
Output:
Enter integer dividend: 8 Enter integer divisor: 0 Divisor cannot be zero. Enter integer divisor: 2 8 modulo 2 has a remainder of 0
Reply


Messages In This Thread
RE: WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! - by ayodele_martins1 - Oct-01-2023, 07:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to revert back to a previous line from user input Sharkenn64u 2 895 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  I think I need to delete input data because returning to start fails thelad 2 1,081 Sep-24-2024, 10:12 AM
Last Post: thelad
  User input with while loops chizzy101010 2 5,201 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  restrict user input to numerical values MCL169 2 1,829 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,954 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 2,332 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 2,298 Dec-11-2022, 07:39 PM
Last Post: snippsat
  Code won't break While loop or go back to the input? MrKnd94 2 1,937 Oct-26-2022, 10:10 AM
Last Post: Larz60+
Sad how to validate user input from database johnconar 3 4,010 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 2,128 Aug-17-2022, 12:43 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020