Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.The following Python program will print whether an input integer number is either an even or an odd number. a.Can you find and explain the

1.The following Python program will print whether an input integer number is either an even or an odd number.

a.Can you find and explain the syntax errors in the program before running it?

b.Run the program and correct the errors.

c.What might be the logic errors in the program? For example, if a user enters a float number (instead of an integer) and other possibilities of input?

# The following program identifies whether an input number is odd or even

inputNumber = int(input('Enter a number: '))

print(type(inputNumber))

print("iinputNumber is:" , inputNumber)

iff inputtNumber%2 == 0 :

print(' You have entered an even number! ')

elsee:

print(' You have entered an odd number! ')

print ('Program ended!')

2.The following Python program calculates average of three input numbers.

a.Run the program and enter the three numbers.Is the output correct?Explain.

b.Correct the program and run it again.

# The following program calculates average of three numbers.

firstNo = float(input('Enter a number: '))

secondNo = float(input('Enter a number: '))

thirdNo = float(input('Enter a number: '))

# Average of the three numbers

averageOfNos = firstNo+ secondNo + thirdNo / 3

print ('The average of the 3 numbers is:', averageOfNos)

print ('Program ended!')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions