Pyhton Coding- Whille Loops How do I get this while loop to continue to run? It quits after one try. Thanks. Here is my coding so far. num=int(input('Enter a three-digit number only (type "1" to quit): '))#check if number of digits in number is 3 or notoddList=[]evenList=[]while num !=1:if len(str(num))==3:#check if number is evenif num%2==0:print("Your number,%s, is even"%(num))evenList.append(int(num))#if number is not even then print oddelse:print("Your number,%s, is odd"%(num))oddList.append(int(num))#first number odd or even#make number a listlistNum=list(str(num))firstNum=listNum[0]#if and else statements for odd or evenif int(firstNum)%2==0:print("%s is even."%(firstNum))evenList.append(int(firstNum))else:print("%s is odd"%(firstNum))oddList.append(int(firstNum))secondNum=listNum[1]if int(secondNum)%2==0:print("%s is even"%(secondNum))evenList.append(int(secondNum))else:print("%s is odd"%(secondNum))oddList.append(int(secondNum))thirdNum=listNum[2]if int(thirdNum)%2==0:print("%s is even"%(thirdNum))evenList.append(int(thirdNum))else:print("%s is odd"%(thirdNum))oddList.append(int(thirdNum))#sum of all digitssum=0#find sum#make string numbers integersfirstNum=int(firstNum)secondNum=int(secondNum)thirdNum=int(thirdNum)sum=firstNum+secondNum+thirdNumprint("The sum of all individual numbers: %s+%s+%s=%s"%(firstNum,secondNum,thirdNum,sum))if sum%2==0:print("%s is an even number"%(sum))evenList.append(int(sum))else:print("%s is an odd number"%(sum))oddList.append(int(sum))print("odd numbers:%s"%(oddList))print("even numbers:%s"%(evenList))#if length of number is not 3 then raise value error exceptionelse:raise ValueErrorbreak

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Pyhton Coding- Whille Loops

How do I get this while loop to continue to run? It quits after one try. Thanks.

Here is my coding so far.

num=int(input('Enter a three-digit number only (type "1" to quit): '))
#check if number of digits in number is 3 or not
oddList=[]
evenList=[]
while num !=1:
if len(str(num))==3:
#check if number is even
if num%2==0:
print("Your number,%s, is even"%(num))
evenList.append(int(num))
#if number is not even then print odd
else:
print("Your number,%s, is odd"%(num))
oddList.append(int(num))
#first number odd or even
#make number a list
listNum=list(str(num))
firstNum=listNum[0]
#if and else statements for odd or even
if int(firstNum)%2==0:
print("%s is even."%(firstNum))
evenList.append(int(firstNum))
else:
print("%s is odd"%(firstNum))
oddList.append(int(firstNum))
secondNum=listNum[1]
if int(secondNum)%2==0:
print("%s is even"%(secondNum))
evenList.append(int(secondNum))
else:
print("%s is odd"%(secondNum))
oddList.append(int(secondNum))
thirdNum=listNum[2]
if int(thirdNum)%2==0:
print("%s is even"%(thirdNum))
evenList.append(int(thirdNum))
else:
print("%s is odd"%(thirdNum))
oddList.append(int(thirdNum))
#sum of all digits
sum=0
#find sum
#make string numbers integers
firstNum=int(firstNum)
secondNum=int(secondNum)
thirdNum=int(thirdNum)
sum=firstNum+secondNum+thirdNum
print("The sum of all individual numbers: %s+%s+%s=%s"%(firstNum,secondNum,thirdNum,sum))
if sum%2==0:
print("%s is an even number"%(sum))
evenList.append(int(sum))
else:
print("%s is an odd number"%(sum))
oddList.append(int(sum))
print("odd numbers:%s"%(oddList))
print("even numbers:%s"%(evenList))
#if length of number is not 3 then raise value error exception
else:
raise ValueError
break

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Binary Search Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education