A. python數據結構輸入一個正整數n,隨機產生n個1-99的整數,使用遞歸演算法求其中的
摘要 一、分支結構
B. python簡單題不會,求解答
#第一題:
from__future__importdivision
print'請依次輸入體重(kg)與身高(m):'
weight=float(raw_input())
height=float(raw_input())
print"{:.2f}".format(weight/(height**2))
#第二題:
print'請輸入一個秒數:'
sec=int(raw_input())
printstr(sec/3600)+''+str(sec%3600/60)+''+str(sec%60)
#第三題:
from__future__importdivision
importmath
print'請依次輸入三角形三邊值a,b,c:'
a=int(raw_input())
b=int(raw_input())
c=int(raw_input())
print"{:.1f}".format(math.degrees(math.acos((a**2+b**2-c**2)/(2*a*b))))
你復制的問題還復制不全,汗啊。。。這么多問題連個分也沒有。。。人家計算BMI是用的平方,你這里還給了個錯的公式,還能不能認真點兒。
C. 按要求寫Python程序計算題
import random
print('a: 加法測試題')
print('b: 乘法測試題')
print('q: 退出')
while True:
a = input('請輸入指令(a/m/q): ')
if (a == 'a'):
for __count in range(5):
f = random.randint(1, 100)
s = random.randint(1, 10)
a = input((str(f) + '+' + str(s) + ' = '))
try:
a = int(a)
except:
print('還需要更細心哦!正確答案是' + str((f + s)))
else:
if (a == f + s):
print('回答正確!你真棒!')
else:
print(('還需要更細心哦!正確答案是' + str((f + s))))
elif (a == 'm'):
for __count in range(5):
f = random.randint(1, 100)
s = random.randint(1, 10)
a = input((str(f) + '×' + str(s) + ' = '))
try:
a = int(a)
except:
print('還需要更細心哦!正確答案是' + str((f * s)))
else:
if (a == f * s):
print('回答正確!你真棒!')
else:
print('還需要更細心哦!正確答案是' + str((f * s)))
elif (a == "q"):
print('小明再見!你會回來!')
D. 如何用python寫問答
使用raw_input(......)列印你的問題,運行後python會把你在裡面輸入的字列印出來,然後你可以回答。在程序中可以將回答設置為變數,然後繼續使用這個回答。(在......處輸入你想輸入的東西,別忘記首尾的冒號)
E. 怎麼用Python做題(急)
#-*-coding:utf-8-*-
#第一題
#py3
defperf(n):
#print(n)
s=0
fortinrange(1,int(n/2+1)):
ifn%t==0:
s+=t
ifs==n:
returnTrue
returnFalse
foriinrange(1,1000):
ifperf(i):
print(i)
#-*-coding:utf-8-*-
#角谷猜想
#py3
n=int(input())
while(n!=1):
print(n,'->',end='')
ifn%2==0:
n=int(n/2)
else:
n=3*n+1
print(n)
F. 有沒有用python寫的在線答題系統
優考試在線考試系統
支持批量導入試題、靈活組卷,可以自動判分,且也有強大的防作弊功能
G. 如何用python解題
第一問:
#python3.6
importturtle
importmath
defdraw_line_in_points():
print("輸入兩個點坐標,繪制並他們和距離。每個點坐標的X和Y用空格分離輸入:")
s1=input("第一個點:")
s2=input("第二個點:")
x1,y1=map(int,s1.split())
x2,y2=map(int,s2.split())
turtle.home()
turtle.pensize(1)
turtle.speed(1)
turtle.hideturtle()
turtle.goto(x1,y1)
turtle.write("({},{})".format(x1,y1))
dis=math.sqrt((x1-x2)**2+(y1-y2)**2)
turtle.left(turtle.towards(x2,y2))
turtle.pendown()
turtle.forward(dis)
turtle.penup()
turtle.write("({},{})".format(x2,y2))
turtle.back(dis//2)
turtle.write("d={}".format(round(dis,2)))
turtle.done()
第二問:
defget_plalindrome_numbers(print_list=True):
#參數print_list用於是否列印出迴文數
xs=10
xd=20000
defplalindrome(x):
x=str(x)
length=len(x)
st=True
forjinrange(length//2+1):
ifx[j]!=x[-j-1]:
st=False
returnst
counter=0
p_list=[]
foriinrange(xs,xd,1):
ifplalindrome(i):
counter+=1
ifprint_list:
p_list.append(i)
print("{}和{}之間的迴文數有{}個。".format(xs,xd,counter))
ifprint_list:
print("它們分別是:{}".format(p_list))
H. Python答題
第10不知道是啥。
#計算圓的面積
importmath
r=float(input('請輸入圓的半徑:'))
area=r**2*math.pi
print(area)
#反向輸出3位數
str=input('請輸入一個三位整數')
new_str=str[::-1]
print(new_str)
#預測身高
whileTrue:
type=input('請選擇測試男女,男孩輸入1,女孩輸入2:')
iftype=='1'ortype=='2':
break
f_height=float(input('請輸入爸爸身高:'))
m_height=float(input('請輸入媽媽身高:'))
iftype=='1':
height=(f_height+m_height)*1.08/2
print('預測男孩身高為:{}'.format(math.floor(height)))
eliftype=='2':
height=(f_height*0.823+m_height)/2
print('預測女孩身高為:{}'.format(math.floor(height)))
else:
print('預測對象選擇錯誤,請重新啟動程序選擇。')
#實數絕對值
importre
importmath
whileTrue:
try:
num=input('請輸入一個實數:')
num=int(num)
break
exceptValueError:
try:
num=float(num)
break
exceptValueError:
continue
#使用abs
num_abs=abs(num)
print('該實數絕對值為:{}'.format(num_abs))
#使用判斷
ifnum>=0:
num_abs=num
else:
num_abs=-num
print('該實數絕對值為:{}'.format(num_abs))
#判斷年份是否為閏年
whileTrue:
try:
year=int(input('請輸入一個年份:'))
break
exceptValueError:
print('輸入錯誤,年份為整數,請重新輸入')
continue
if(year%100==0):
if(year%400==0):
print('年份{}為閏年'.format(year))
else:
print('年份{}為平年'.format(year))
elif(year%4==0):
print('年份{}為閏年'.format(year))
else:
print('年份{}為平年'.format(year))
#繳納學費
whileTrue:
try:
I=int(input('請輸入學生學號:'))
break
exceptValueError:
print('輸入錯誤')
continue
whileTrue:
try:
U=int(input('請輸入該學生學分:'))
break
exceptValueError:
print('輸入錯誤')
continue
ifU<=12:
T=4000
else:
T=4000+200*(U-12)
print('學生{}應繳納學分為{}'.format(I,T))
#登錄
username='123'
password='456'
whileTrue:
user=input('請輸入用戶名:')
pw=input('請輸入密碼:')
if(user==usernameandpw==password):
print('歡迎使用!')
break
else:
print('用戶名或密碼錯誤,請重新輸入!')
#判斷輸入字元
whileTrue:
str=input('請輸入一個字元')
if(len(str)==1):
break
else:
print('輸入錯誤,請重新輸入')
str_code=ord(str)
ifstr_code>=48andstr_code<=57:
print('{}是一個數字'.format(str))
elifstr_code>=65andstr_code<=90:
print('{}是一個大寫字母'.format(str))
elifstr_code>=97andstr_code<=122:
print('{}是一個小寫字母'.format(str))
else:
print('{}既不是數字,也不是大小寫字母'.format(str))
#判斷成績
whileTrue:
try:
grade=int(input('請輸入成績:'))
if(grade>=0andgrade<=100):
break
else:
print('成績輸入錯誤,請重新輸入')
continue
exceptValueError:
print('成績輸入錯誤,請重新輸入')
continue
ifgrade>=90:
print('優秀')
elifgrade>=80:
print('良好')
elifgrade>=70:
print('中等')
elifgrade>=60:
print('及格')
else:
print('不及格')
I. 如何用python寫一個從題庫自動匹配的答題腳本
#!/usr/bin/envpythonimportsysstr=Truewhile(str):dig=int(input())ifdig>100:print'pleaseinputmunbetween0~100'elifdig>=90:print'A'elifdig>=80:print'B'elifdig>=70:print'C'elifdig>=60:prin