0% found this document useful (0 votes)
153 views6 pages

From Import: Math Pi, Tan Side ( ) Area ( Side ) / Tan (Pi/) (Area)

The document contains solutions to 5 programming questions: 1) a program to calculate the area of a pentagon, 2) a payroll calculator, 3) a program to check if a number is divisible by 5 and/or 6, 4) a lottery number matching game, 5) a program to check if a point lies within, outside, or on a circle.

Uploaded by

Simbha Laloo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views6 pages

From Import: Math Pi, Tan Side ( ) Area ( Side ) / Tan (Pi/) (Area)

The document contains solutions to 5 programming questions: 1) a program to calculate the area of a pentagon, 2) a payroll calculator, 3) a program to check if a number is divisible by 5 and/or 6, 4) a lottery number matching game, 5) a program to check if a point lies within, outside, or on a circle.

Uploaded by

Simbha Laloo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Question 1:

The area of a pentagon can be computed using the following formula (s is the length of a side):

Write a program that prompts the user to enter the side of a pentagon and displays the area
Answer:

from math import pi, tan


side = eval(input("Enter the side: "))
area = (5 * side ** 2)/4 * tan (pi/5)
print(f"The area of the pentagon is {area}")

Run:

Enter the side: 4

The area of the pentagon is 14.530850560107215

Question 2:

Q. 2. Write a program that reads the following information and prints a payroll statement:
 Employee’s name (e.g., Smith)
 Number of hours worked in a week (e.g., 10)
 Hourly pay rate (e.g., 9.75)
 Federal tax withholding rate (e.g., 20%)
 State tax withholding rate (e.g., 9%)

Answer:

name = input("enter the name of employee:")


hours = eval(input("enter number of hours worked:"))
payrate = eval(input("enter the hourly payrate:"))
federate = eval(input("enter federal tax withholding rate:"))
state_rate = eval(input(" enter state tax withholding rate:"))
print("Employee name:",name, "\n"
"hours worked:",hours, "\n"
"pay rate: $", payrate, "\n"
"gross_pay: $", hours* payrate, "\n"
"deduction:\n"
"\t federal withholding (30.0%):$",(federate) * (hours*payrate), '\n'
"\t state withholding (30.0%):$",(state_rate) * (hours*payrate), '\n'
"\t total deduction:$",((federate) * (hours*payrate)+ (state_rate*(hours*payrate)), '\n'
"net pay:$",(hours*payrate)-(((federate)*(hours*payrate))+(state_rate*(hours*payrate))))

Question 3:

. Write a program that prompts the user to enter an integer and checks whether the number is
divisible by both 5 and 6, divisible by 5 or 6, or just one of them (but not both)

Answer:

num = eval(input("Enter your number: "))

if num % 5 == 0 and num % 6 == 0:


print("Is num divisible by 5 and 6?",True)
else:
print("Is num divisible by 5 and 6?",False)

if num % 5 == 0 or num % 6 == 0:
print("Is num divisible by 5 or 6?",True)
else:
print("Is num divisible by 5 or 6?",False)

if (num % 5 == 0 and num % 6 != 0) or (num % 5 != 0 and num % 6 == 0):


print("Is num divisible by 5 or 6, but not both?",True)
else:
print("Is num divisible by 5 or 6, but not both?",False)
Run:

Enter your number: 8

Is num divisible by 5 and 6? False

Is num divisible by 5 or 6? False

Is num divisible by 5 or 6, but not both? False


Question 4:

(Game: lottery) The program prompts the user to enter a three-digit number and determines
whether the user wins according to the following rules:
a. If the user input matches the lottery number in the exact order, the award is $10,000.
b. If all the digits in the user input match all the digits in the lottery number, the award is
$3,000.
c. If one digit in the user input matches a digit in the lottery number, the award is $1,000.

Answer:

import random

# Generate a lottery

lottery = random.randint(0, 99)


lottery_num = 57

guess = int(input("Enter your lottery pick (two digits): "))

lottery_Digit1 = lottery // 10
lottery_Digit2 = lottery % 10

# digits from guess


guess_Digit1 = guess // 10

guess_Digit2 = guess % 10

print("The lottery number is", lottery)


# Check the guess
if guess == lottery_num:
print("All match: you win $10,000")
elif (guess_Digit2 == lottery_Digit1 and
guess_Digit1 == lottery_Digit2):
print("all digits match: you win $3,000")
elif (guess_Digit1 == lottery_Digit1 and
guess_Digit1 == lottery_Digit2 and
guess_Digit2 == lottery_Digit1 and
guess_Digit2 == lottery_Digit2):
print("One digit match: you win $1,000")
else:
print("Sorry, no digit match")

Question 5:

Write a program that prompts the user to enter a point (x, y) and checks whether the point is
within the circle centered at (0, 0) with radius 10. For example, (4, 5) is inside the circle and (9,
9) is outside the circle.
Answer:

import math

m , n = 0,0
m1 , n1 = eval(input("enter value of x and y co-ordinate of a point: "))
r = 10

distance = math.sqrt(((m1-m)*2)+((n1-n)*2))

if distance < r:
print("the point are inside the circle")

elif distance > r:


print("the point are outside the circle")

elif distance == r:
print("point is on the circle")

Run:
enter value of x and y co-ordinate of a point: 5,8
the point are inside the circle

You might also like