Question

Write a python program that requests a positive four-digit integer from the user and prints the...

  1. Write a python program that requests a positive four-digit integer from the user and prints the total of the digits. You are not allowed to use the string data type operations. The program should read it as an integer and process it as an integer. Use a while loop.

SAMPLE

Enter four digit integer: 1234

10

  1. Write a python program that requests four integers from the user. The program should compute the average of the first three numbers and compare the average to the fourth number. If they are equal, the program should print ’Equal’ on the screen. If they are not equal, the program should print ‘Not Equal’.

SAMPLE

Enter first integer: 1

Enter second integer: 2

Enter third number: 3

Enter fourth integer: 2

Equal

  1. Write a python program that calculates parking charges. The program will read in the hours to be charged and will calculate the charges as follows: The first hour is $5. Hours 2 – 5 are $50 each. Hours over 5 is $2.00 each. Print the total charges. Use an if/else structure.

SAMPLE

Enter hours: 4

The charge is $ 15.50

0 0
Add a comment Improve this question Transcribed image text
Answer #1

n = int(input("Enter four digit integer: "))
s = 0
while(n>0):
    s += (n%10)
    n=n//10
print(s)

n1 = int(input("Enter first integer: "))
n2 = int(input("Enter second integer: "))
n3 = int(input("Enter third integer: "))
n4 = int(input("Enter fourth integer: "))
avg = (n1+n2+n3)/3
if(avg == n4):
    print("Equal")
else:
    print("Not Equal")

n = int(input("Enter hours: "))
s = 0
if(n==1):
    s = 5
elif(n<=5):
    s = 5 + (n-1)*50
else:
    s = 5 + 4*50 + (n-5)*2
print("The charge is $%.2f"%(s/10))
Add a comment
Know the answer?
Add Answer to:
Write a python program that requests a positive four-digit integer from the user and prints the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT