python day 03 homework

第一题

在这里插入图片描述

import math
r = eval(input('Enter the length from the center to a vertex:'))
s = 2 * r * math.sin(math.pi/5) 
area = 5 * s ** 2 / (4 * math.tan(math.pi/5))
print('The area of the pentagon is %.2f'%area)

第二题

在这里插入图片描述

import math
x1,y1 = eval(input('Enter point 1 (latitude and longitude) in degrees:'))
x2,y2 = eval(input('Enter point2(latitude and longitude) in degrees:'))
radius = 6371.01
x11 = math.radians(x1)
y11 = math.radians(y1)
x22 = math.radians(x2)
y22 = math.radians(y2)
d = radius * math.acos(math.sin(x11) * math.sin(x22) + math.cos(x11) * math.cos(x22) * math.cos(y11-y22))
print('The distance between the two points is %.14f km'%d)

第三题

在这里插入图片描述

import math
s = eval(input('Enter the side :'))
area = (5 * s ** 2) / (4 * math.tan(math.pi/5))
print('The area of the pentagon is %.14f'%area)

在这里插入图片描述

第四题

import math 
num = eval(input('Enter the number of side :'))
s = eval(input('Enter the side :'))
area = (num * s ** 2) / (4 * math.tan(math.pi / num))
print('The area of the polygon is %.14f'%area)

第五题

a = eval(input('Enter an ASCII code :'))
print(chr(a))

第六题

在这里插入图片描述

name = input('Enter employee’s name :')
hours = eval(input('Enter number of hours worked in a week :'))
pay = eval(input('Enter hosrly pay tate :'))
federal = eval(input('Enter federal tax withholding rate :'))
state = eval(input('Enter state tax withholding rate :'))
print('Employee Name :%s'%name)
print('Hours Worked :%s'%hours)
print('Pay Rate :$%s'%pay)
gross = hours * pay
print('Gross Pay :$%.2f'%gross)
print('Deductions:')
a = federal * 100
b = gross * federal  
print('  Federal Withholding (%s%%) :$%.2f'%(a,b))
c = state * 100
d = gross * state
print('  State Withholding (%s%%) :$%.2f'%(c,d)) 
res = b + d 
print('  Total Deduction : $%.2f'%res)
net = gross - res
print('Net Pay : $%.2f'%net)

在这里插入图片描述

第七题

strA = input('Enter an number :')
print('The reversed number is %s'%strA[::-1])

第八题

a = input('请输入一串文本:')
print('即将进行加密,请稍等!!!')
for i in a :
    b = ord(i)
    c = b + 10
    d = chr(c-19)
    print(d,end=" ")

第九题

在这里插入图片描述

import math 
a , b , c = map(int, input('Enter a, b, c :').split(','))
num = b ** 2 - 4 * a * c 
if  num > 0 :
    r1 = (-b + math.sqrt(num))/(a * 2)
    r2 = (-b - math.sqrt(num))/(a * 2)
    print('The roots are %g and %g '%(r1,r2))
elif num == 0:
    r = (-b + math.sqrt(num))/(a * 2)
    print('The root is %g'%r)
else :
    print('The equation has no real roots')

第十题

在这里插入图片描述

import random 
num1 = random.randint(0,101)
num2 = random.randint(0,101)
he = num1 + num2 
print('欢迎来到猜数字游戏!!!')
print('下面将随机生成两个一百以内的整数')
print('***     ***')
res = int(input('请输入你认为这两个数字的和:'))
if res == he :
    print('you are winner!!!')
else:
    print('you are loser !!!')

第十一题

today = int(input('Enter today’s day :'))
sin = int(input('Enter the number of days elapsed sine today :'))
a = sin % 7
b = today + a 
l = 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'
if b > 6 :
    c = b - 7
    print('Today is %s and the future day is %s'%(l[today],l[c]))
else   : 
    c = b
    print('Today is %s and the future day is %s'%(l[today],l[c]))

第十二题

a , b , c = map(int, input('请输入需要排序的三个整数').split(','))
print('数据排序中,请稍后!!!')
if a > b > c :
    print(c, b, a)
elif a > c > b :
    print(b, c, a)
elif b > a > c :
    print(c, a, b)
elif b > c > a :
    print(a, c, b)
elif c > a > b :
    print(b, a, c)
else :
    print(a, b, c)

第十三题

在这里插入图片描述

a , b  = map(float, input('Enter  weight and price for package 1 :').split(','))
c , d  = map(float, input('Enter  weight and price for package 2 :').split(','))
p1 = b / a 
p2 = d / c
if  p1 > p2:
    print('Package 2 has the better peice.')
else:
    print('Package 1 has the better peice.')

第十四题

month=int(input('请输入月份>>>'))
year=int(input('请输入年份>>>'))
if (year%4==0 and year%100!=0) or (year%400==0):
    i = {1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
    print(i[month])
else:
    j = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
    print(j[month])

第十五题

import random
i = random.randint(1,2)
res = int(input('请输入猜测的硬币的正反面(正面为1,反面为2):'))
if i == res:
    print('你猜对了!!!')
else:
    print('你猜错了!!!') 

第十六题

import numpy as np 
computer = np.random.randint(0,3)
print(computer)
you = int(input('scissor(0),rock(1),paper(2):'))
ku = 'scissor','rock','paper'
if computer == you :
    print('The computer is %s.you are %s too .It is a draw.'%(ku[computer],ku[you]))
elif computer == 0 and you == 2 :
    print('The comeputer is %s.You are %s.You lose. '%(ku[computer],ku[you]))
elif computer == 1 and you == 0 :
    print('The comeputer is %s.You are %s.You lose. '%(ku[computer],ku[you]))
elif computer == 2 and you == 1 :
    print('The comeputer is %s.You are %s.You lose. '%(ku[computer],ku[you]))
else :
    print('The comeputer is %s.You are %s.You won. '%(ku[computer],ku[you]))

第十七题

在这里插入图片描述

import math
a = 'Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday'
y= int(input('Enter year: (e.g., 2008): '))
m = int(input('Enter month : 1-12 :'))
d = int(input('Enter the day of the month: 1-31:'))
k  = y % 100
j =  y // 100 
if m == 1 or m == 2 :
    m_ = m + 12 
    y_ = y - 1
    k = y_ % 100
    j = y_ // 100
    h = (d + (26 * (m_ + 1) / 10) + k + (k / 4) + (j / 4) + (5 * j) ) % 7
    print(a[math.floor(h)])
else :
    h = (d + (26 * (m + 1) / 10) + k + (k / 4) + (j / 4) + (5 * j) ) % 7
    print(a[math.floor(h)])

在这里插入图片描述

第十八题

import numpy as np
num = np.random.randint(0,13)
c = np.random.randint(0,4)
a = 'Ace','2','3','4','5','6','7','8','9','10','jack','Queen','King'
b = 'Clubs','diamonds','spades','hearts'
print('The card you picked is the %s of %s'%(a[num],b[c])

第十九题

a = str(input('Enter a three-digit integer :'))
if a[0] == a[2]:
    print('%s is a palindrome '%a)
else :
    print('%s is not a palindrome'%a)

第二十题

a , b , c = map(int,input('Enter three edges :').split(','))
if a + b > c and a + c > b and b + c > a :
    d = a + b + c
    print('the perimeter is %g'%d)
else :
    print('输入不合法!!!')

第二十一题

在这里插入图片描述

num1 = 0
num2 = 0
he = 0
for i in range(200):
    a = int(input('请输入整数:'))
    
    if a == 0:
        break
    else:
        if a > 0 :
            num1 += 1
        else  :
            num2 += 1
    he += a
ping =float( he / (num1 + num2))
print('您输入的正数有%d个,负数有%d个,平均值是%g'%(num1,num2,ping))

第二十二题

在这里插入图片描述

j = 10
money = 10000
money_pay = 0
money_tan = 10000 *(1+0.05)**10
for  i in range(4):
    if i < 4:
        j += 1
        money_now = 10000 * (1+0.05) ** j
    else:
        break
    money_pay += money_now
print('十年后的学费为:$%.2f,十年后大学四年的学费为:$%.2f'%(money_tan,money_pay))

第二十三题

在这里插入图片描述

('题目详情请见第二十一题')

第二十四题

num = 0
for i in range(100,1000):
    if i % 5 == 0 and i % 6 == 0:
        print(i,end = " ")
        num += 1

第二十五题

在这里插入图片描述

n = 1
while n  < 500:
    if n ** 2 > 12000:
        print(n)
        break
    else :
        n += 1
m = 1
i = 0 
while m < 100:
    if m ** 3 > 12000:
        i = m - 1
        print(i)
        break
    else :
        m += 1

第二十六题

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值