import math
import random
def calculate_square_root():
a,b,c = eval(input("Enter a , b , c:"))
discriminant= b**2 - 4 * a * c
if discriminant > 0:
r1 = (-b + math.sqrt(b**2 - 4*a*c))/2 * a
r2 = (-b - math.sqrt(b**2 - 4*a*c))/2 * a
print("The roots are %.2f"%r1,"and%.2f"%r2)
elif discriminant==0:
r1 = r2 = (-b + math.sqrt(b**2 - 4 * a * c))/2 * a
print("The roots are %.2f"%r1)
else:
print("The equation has no real roots!")
def Cramer_rule():
a,b,c,d,e,f=eval(input("请输入6个相关系数: "))
x=(e*d-b*f)/(a*d-b*c)
y=(a*f-e*c)/(a*d-b*c)
if a*b-b*c!=0:
print("二元一次方程组的解为x= : ",x)
print("二元一次方程组的解为y= : ",y)
else:
print("无解")
def practice_add():
number1 = random.randint(0,100)
number2 = random.randint(0,100)
answer = eval(input(str(number1)+'+'+str(number2)+'=?'))
print(number1,"+",number2,"=",answer,"is",number1+number2==answer)
def find_future_date():
week_day = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
today = int(input("Enter today's day:"))
future_day = int(input("Enter the number of days elapsed since today: "))
weekday = today % 7
future_weekday = (today + future_day)%7
print("Today is ",week_day[weekday],"and the future day is ",week_day[future_day])
def arrange_num():
a,b,c= eval(input("请输入三个整数:"))
list1 = [a,b,c]
list1.sort()## 直接对列表进行操作,无需使用列表=
for i in list1:
print(i)
def find_month_days():
month_days = ["31",'29',"31","30","31","30","31","31","30","30","30","31"]
year,month = eval(input("Enter the year and month:"))
if year % 400 == 0 and month == 2:
print("%d 年 %d 月有 28 天"%(year,month))
elif year % 400 != 0:
print("%d 年 %d 月 有 %s 天"%(year,month,month_days[month-1]))
# 此处隐藏知识点:elif 和 if 循环语句的差别,if与if条件是对立存在的,即if后的条件都会进行判断显示,而if与elif则是if判断成立后,不会继续判断elif后的条件。
def Rock_paper_scissors():
bunch = input("石头,剪刀,布:")
bunch_library = ['石头','剪刀','布']
computer = bunch_library[random.randint(0,2)]
# randint函数是包含 2 的
# 玩家角度
if ((bunch == '石头')and (computer == '剪刀'))or((bunch == '剪刀')and(computer == '布')) or((bunch == '布')and(computer == "石头")):
print("电脑是%s"%computer,"你赢了")
elif bunch == computer:
print("电脑是%s"%computer,"平局")
else:
print("电脑是%s"%computer,"你输了")
def calculate_the_week():
week_day = ['Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday']
year = eval(input("Enter year :(e.g.,2008):"))
m = eval(input("Enter month:1-12:"))
if m == 1 or m == 2:
m += 12
year -= 1
q = eval(input("Enter the day of month:1-31:"))
k = year % 100
j = (year / 100)//1
h = ((q + (26*(m + 1)/10)//1) + k + ((k/4)//1) + ((j/ 4) //1+5 *j)) % 7
print("Day of the week is %s"%week_day[int(h)])
def judge_palindromic_number():
number = eval(input("Enter a three_digit integer:"))
a = number // 100
c = number % 10
if a == c:
print("%d is a palindrome"%number)
else:
print("%d is not a palindrome"%number)
def tansfer_digit():
digit = eval(input("输入十进制数:"))
convertion = eval(input("输入要转换的进制(2、8、16)"))
if convertion == 2:
num = bin(digit)
elif convertion == 8:
num = oct(digit)
elif convertion == 16:
num = hex(digit)
print(num)
if __name__ == '__main__':
tansfer_digit()
且行且珍惜