DMV_sums6.py - C:/Users/shell/OneDrive/Desktop/DMV_sums6.py (3.8.2) File Edit Format Run Options Window Help #!/usr/bin/env python3 # Shelly Voelker \t # COP2002.OM2 # March 13, 2020 # Sums # This program uses input from the user to calculate the sum of all odd or even # display a welcome message print ("Sums of Odd and Even Numbers") print () #user input choice='y' #while loop for repeating the exercise while (choice=='y'): #prompt user to enter a number num=int (input ("Please enter a number between 1 and 50:")) #while loop while (num50) : #prompt user to enter a number between 1 and 50 num=int (input ("Please try again. Your number must be between 1 and 50: ") #if the number is even if (num$2==0) #display the message print ("\nYour number is an even number.") #initialize the value of sum sum=0 #calculation of sum of even numbers for i in range (2, num+1,2) : sum+=i #displaying the sum of even numbers print ("The sum of even numbers ranging from 2 to ,num, is:", sum) else: print ("\nYour number is an odd number.") sum=0 #calculation of sum of odd numbers for i in range (1, num+1,2): sum+=i #displaying the sum of odd numbers print ("The sum of the odd numbers ranging from 1 to hum, " is:", sum) choice=input ("\nDo you want to try again? (y/n) ") Ln: 41 Col: 4

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter12: Exception Handling
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

I keep getting a syntax error ("invalid syntax") when I try to run my program.

How can I fix this error?

DMV_sums6.py - C:/Users/shell/OneDrive/Desktop/DMV_sums6.py (3.8.2)
File
Edit
Format
Run Options Window Help
#!/usr/bin/env python3
# Shelly Voelker \t
# COP2002.OM2
# March 13, 2020
# Sums
# This program uses input from the user to calculate the sum of all odd or even
# display a welcome message
print ("Sums of Odd and Even Numbers")
print ()
#user input
choice='y'
#while loop for repeating the exercise
while (choice=='y'):
#prompt user to enter a number
num=int (input ("Please enter a number between 1 and 50:"))
#while loop
while (num<l or num>50) :
#prompt user to enter a number between 1 and 50
num=int (input ("Please try again. Your number must be between 1 and 50: ")
#if the number is even
if (num$2==0)
#display the message
print ("\nYour number is an even number.")
#initialize the value of sum
sum=0
#calculation of sum of even numbers
for i in range (2, num+1,2) :
sum+=i
#displaying the sum of even numbers
print ("The sum of even numbers ranging from 2 to
,num,
is:", sum)
else:
print ("\nYour number is an odd number.")
sum=0
#calculation of sum of odd numbers
for i in range (1, num+1,2):
sum+=i
#displaying the sum of odd numbers
print ("The sum of the odd numbers ranging from 1 to
hum,
" is:", sum)
choice=input ("\nDo you want to try again? (y/n) ")
Ln: 41 Col: 4
Transcribed Image Text:DMV_sums6.py - C:/Users/shell/OneDrive/Desktop/DMV_sums6.py (3.8.2) File Edit Format Run Options Window Help #!/usr/bin/env python3 # Shelly Voelker \t # COP2002.OM2 # March 13, 2020 # Sums # This program uses input from the user to calculate the sum of all odd or even # display a welcome message print ("Sums of Odd and Even Numbers") print () #user input choice='y' #while loop for repeating the exercise while (choice=='y'): #prompt user to enter a number num=int (input ("Please enter a number between 1 and 50:")) #while loop while (num<l or num>50) : #prompt user to enter a number between 1 and 50 num=int (input ("Please try again. Your number must be between 1 and 50: ") #if the number is even if (num$2==0) #display the message print ("\nYour number is an even number.") #initialize the value of sum sum=0 #calculation of sum of even numbers for i in range (2, num+1,2) : sum+=i #displaying the sum of even numbers print ("The sum of even numbers ranging from 2 to ,num, is:", sum) else: print ("\nYour number is an odd number.") sum=0 #calculation of sum of odd numbers for i in range (1, num+1,2): sum+=i #displaying the sum of odd numbers print ("The sum of the odd numbers ranging from 1 to hum, " is:", sum) choice=input ("\nDo you want to try again? (y/n) ") Ln: 41 Col: 4
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
Structure chart
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,