defisPrime(number):
divisor =2while divisor <= number /2:if number % divisor ==0:returnFalse
divisor +=1returnTruedefinverse_prime(number):if number <=99:
b = number %100//10
c = number %100%10returnf"{c}{b} "elif number >=100:
a = number //100
b = number %100//10
c = number %100%10returnf"{c}{b}{a}"defprint_prime_numbers(number_of_primes):
number_of_primes_per_line =10
count =0
number =2while count < number_of_primes:if isPrime(number):
count +=1
a = inverse_prime(number)print(format(a,">4"), end=" ")if count % number_of_primes_per_line ==0:print()
number +=1defmain():print("The first 100 prime number are")
print_prime_numbers(100)
main()
defisPrime(number):
divisor =2while divisor <= number /2:if number % divisor ==0:returnFalse
divisor +=1returnTruedefmersenne_prime(number):
a =2** number -1returnformat(a,"<10d")defprint_number(number):
number_of_primes_per_line =31
count =0while count < number_of_primes_per_line:
count +=1if isPrime(number):print(f"This %2d is mersenne prime,"% number, mersenne_prime(number))
number +=1defmain():
print_number(2)
main()
这个代码的编写思想,我承认很无耻。
defisPrime(number):
divisor =2while divisor <= number /2:if number % divisor ==0:returnFalse
divisor +=1returnTruedefcontrast(number):
a = number +2print(a)defprintPrimeNumbers(number_of_primes):
count =0
number =3while count < number_of_primes:if isPrime(number):print(number, end=" ")
contrast(number)
count +=1
number +=1defmain():print("The less than 1000 prime number are")
printPrimeNumbers(999)
main()
from random import*defplus_method(num1, num2):
a = num1 + num2
return a
defmain():whileTrue:
num1 = randint(0,6)
num2 = randint(0,6)
a = plus_method(num1, num2)if a ==2or a ==3or a ==12:print(f"{num1} + {num2} = {a}")print("You lose")breakelif a ==7or a ==11:print(f"{num1} + {num2} = {a}")print("You Win")breakelse:print(f"{num1} + {num2} = {a}")print(f"Point is {a}")continue
main()
defn_odd(number):
a = number //1000
a_m = a *2
c = number %1000//10%10
c_m = c *2if a_m >=10and c_m <=9:
odd_a_1 = a_m //10
odd_a_2 = a_m %10
odd_a_sum = odd_a_1 + odd_a_2
return odd_a_sum + c_m
elif c_m >=10and a_m <=9:
odd_c_1 = c_m //10
odd_c_2 = c_m %10
odd_c_sum = odd_c_1 + odd_c_2
return odd_c_sum + a_m
elif a_m >=10and c_m >=10:
odd_a_1 = a_m //10
odd_a_2 = a_m %10
odd_a_sum = odd_a_1 + odd_a_2
odd_c_1 = c_m //10
odd_c_2 = c_m %10
odd_c_sum = odd_c_1 + odd_c_2
return odd_c_sum + odd_a_sum
elif a_m <=9and c_m <=9:return a_m + c_m
defn_even(number):
b = number %1000//100
d = number %10return b + d
defisValid(n1, n2, n3, n4, a, b):
c = a + b
d = c %10if d ==0:print(f"This {str(n1)}{str(n2)}{str(n3)}{str(n4)} credit card is valid")print(d)print(c)else:print(f"This {str(n1)}{str(n2)}{str(n3)}{str(n4)} credit card is invalid")print(d)print(c)defmain():# number1 = eval(input("Input credit card number: "))# number2 = eval(input("Input credit card number: "))# number3 = eval(input("Input credit card number: "))# number4 = eval(input("Input credit card number: "))
number1 =4388
number2 =5760
number3 =1840
number4 =2626# 2001是valid
a = n_odd(number1)+ n_odd(number2)+ n_odd(number3)+ n_odd(number4)
b = n_even(number1)+ n_even(number2)+ n_even(number3)+ n_even(number4)
isValid(number1, number2, number3, number4, a, b)
main()
from random import*defplus_method(num1, num2):
a = num1 + num2
return a
defmain():
count =1
you_win =1
you_lose =1
with_draw =1while count <=10000:
count +=1
num1 = randint(0,6)
num2 = randint(0,6)
a = plus_method(num1, num2)if a ==2or a ==3or a ==12:print(f"{num1} + {num2} = {a}")print("You lose")
you_lose +=1elif a ==7or a ==11:print(f"{num1} + {num2} = {a}")print("You Win")
you_win +=1else:print(f"{num1} + {num2} = {a}")print(f"Point is {a}")
with_draw +=1print(f"You win is {you_win} and you lose is {you_lose} with draw {with_draw}")
main()
import time
defcurrent_time():
cu_time = time.time()return cu_time
deftotal_seconds():
to_seconds =int(current_time())return to_seconds
defcurrent_seconds():
cu_seconds = total_seconds()%60return cu_seconds
deftotal_minutes():
to_minutes = total_seconds()//60return to_minutes
defcurrent_minutes():
cu_minutes = total_minutes()%60return cu_minutes
defcurrent_hour():
total_hours = total_minutes()//60
cu_hour = total_hours %24return cu_hour +8deftotal_day():# compute to since 1970.01.01 second
total_hours = total_minutes()//60//24return total_hours
defrun_day_in_year():# This is the best part
year =1970
a = total_day()while a >=366:if is_leap_year(year):
a -=366else:
a -=365
year +=1return a
#defcurrent_year():# I don't know how to call the two results separately,right
year =1970
a = total_day()while a >=366:if is_leap_year(year):
a -=366else:
a -=365
year +=1return year
defget_month_name(month):if month ==1:
month_name ="January"elif month ==2:
month_name ="February"elif month ==3:
month_name ="March"elif month ==4:
month_name ="April"elif month ==5:
month_name ="May"elif month ==6:
month_name ="June"elif month ==7:
month_name ="July"elif month ==8:
month_name ="August"elif month ==9:
month_name ="September"elif month ==10:
month_name ="October"elif month ==11:
month_name ="November"else:
month_name ="December"return month_name
defis_leap_year(year):return year %400==0or(year %4==0and year %100!=0)defcurrent_day():
a = run_day_in_year()
month_day =1
month_text = month_day
while a >=28:
month_day +=1if month_day ==1or month_day ==3or month_day ==5or month_day ==7or month_day ==8or \
month_day ==10or month_day ==12:
a -=31if month_day ==4or month_day ==6or month_day ==9or month_day ==11:
a -=30if month_day ==2:if is_leap_year(current_year()):
a -=29else:
a -=28print(f"current day is {a +1} and {get_month_name(month_day)}")defmain():print("This year is", current_year())
current_day()print("Current time is", current_hour(),":",
current_minutes(),":", current_seconds(),"GMT")
main()
defmonth_list(month_data):
month_dist ={1:"一月",2:"二月",3:"三月",4:"四月",5:"五月",6:"六月",7:"七月",8:"八月",9:"九月",10:"十月",11:"十一月",12:"十二月"}return month_dist[month_data]defweek_list(w_day):
week_dist ={0:"星期六",1:"星期日",2:"星期一",3:"星期二",4:"星期三",5:"星期四",6:"星期五"}return week_dist[w_day]defcount_day(year_data, month_num, input_data):
year_data_type = year_data
after_years = year_data -1for i inrange(month_num,13):
month_day = i
if i <=2:
i +=12
year_data = after_years
elif i >=3:
i = i
year_data = year_data_type
# print(i,year_data)
j = year_data //100
k = year_data %100
m1 =(26*(i +1))//10
w_day =(input_data + m1 + k +(k //4)+(j //4)+(5* j))%7print(month_list(month_day), input_data, year_data_type,"is", week_list(w_day))defmain():
year_data =eval(input("Enter year number is: "))
month_num =eval(input("Enter month number is: "))
input_data =eval(input("Enter day number is: "))
count_day(year_data, month_num, input_data)
main()