Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Booleans in Python
#5
(Apr-22-2020, 09:25 AM)anbu23 Wrote: Output of input() is of string type. So no need to use str(). This code will exit loop when you enter other than Y for input('Another number? ')

while True:
  num = int(input('Please enter a number: '))
  print('Number you entered is ' + ('even' if num%2 == 0 else 'odd'))
  proceed = input('Another number? ')
  if proceed.upper() != 'Y':
      break

Thank you so much Anbu23!
Reply


Messages In This Thread
Booleans in Python - by azure - Apr-22-2020, 07:16 AM
RE: Booleans in Python - by anbu23 - Apr-22-2020, 08:10 AM
RE: Booleans in Python - by azure - Apr-22-2020, 08:54 AM
RE: Booleans in Python - by anbu23 - Apr-22-2020, 09:25 AM
RE: Booleans in Python - by azure - Apr-22-2020, 11:58 AM
RE: Booleans in Python - by perfringo - Apr-22-2020, 02:16 PM
RE: Booleans in Python - by azure - Apr-24-2020, 07:05 AM

Forum Jump:

User Panel Messages

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