python的字串 綜合練習題

2021-10-01 13:18:37 字數 3677 閱讀 1640

設計乙個程式,幫助小學生練習10以內的加法

詳情:

- import random  # 匯入隨機數的函式庫

all_number =

0 # 答題總數定義為0

right_number =

0 # 正確總數定義為0

for i in range(1

,100

): ##迴圈1~100個加法題

student_choose =

int(

input

('做題模式1、退出模式2'))

if student_choose ==1:

num1 = random.

randint(1

,10) num2 = random.

randint(1

,10) answer = num1 + num2 ##內部求和

print

('%d+%d=___'

%(num1, num2)

) student_answer =

int(

input

('請輸入正確答案:'))

if student_answer == answer:

right_number +=1

all_number +=1

i +=1

else

: all_number +=1

i +=1

else

:print

('bye!!!'

)break

precision=right_number/all_number*

100print

('你總共答了%d題,做對了%d題,正確率為%.2f%%'

結果練習二

小學生算術能力測試系統:

設計乙個程式,用來實現幫助小學生進行百以內的算術練習,

它具有以下功能:提供9道加、減、乘或除四種基本算術運算的題目;

練習者根據顯示的題目輸入自己的答案,

程式自動判斷輸入的答案是否正確並顯示出相應的資訊。

import random

all_number =

0right_number =

0for i in range(1

,10):

student_choose =

int(

input

('請選擇模式-1答題,2退出:'))

if student_choose ==1:

num1 = random.

randint(1

,100

) num2 = random.

randint(1

,100

)# if num1 < num2:

# a = num1

# num1 = num2

# num2 = a

offer_choose =

['+'

,'-'

,'*'

,'/'

] already_choose = random.

choice

(offer_choose)

if already_choose ==

'+':

answer = num1 + num2

print

('%d+%d=__'

%(num1, num2)

) student_answer =

int(

input

('請給出你的答案:'))

if student_answer == answer:

all_number +=1

right_number +=1

i +=1

else

: all_number +=1

i +=1

if already_choose ==

'-':

answer = num1 - num2

print

('%d-%d=__'

%(num1, num2)

) student_answer =

int(

input

('請給出你的答案:'))

if student_answer == answer:

all_number +=1

right_number +=1

i +=1

else

: all_number +=1

i +=1

if already_choose ==

'*':

answer = num1 * num2

print

('%d*%d=__'

%(num1, num2)

) student_answer =

int(

input

('請給出你的答案:'))

if student_answer == answer:

all_number +=1

right_number +=1

i +=1

else

: all_number +=1

i +=1

if already_choose ==

'/':

answer = num1 / num2

print

('%d/%d=__'

%(num1, num2)

) student_answer =

float

(input

('請給出你的答案:'))

if student_answer == answer:

all_number +=1

right_number +=1

i +=1

else

: all_number +=1

i +=1

else

:print

('bye!!!'

)break

precision = right_number / all_number *

100print

('你總共答了%d題,答對了%d道,正確率為%.2f%%'

%(all_number, right_number, precision)

)if precision >

60.00

:print

('恭喜你,算術練習過關,再接再礪!!!'

)else

:print

('算術練習不過關,別灰心,加油!!!'

)

結果

字串練習題

1.請編寫乙個c函式,該函式可以實現將乙個整數轉為任意進製的字串輸出 include include char ch 16 函式宣告 將整數轉換為任意進製的字串 charchar int2sys int num,int n,int move bit int main else if n 8 else...

字串練習題

變數名是否合法 1.變數名只能由字母 數字 下劃線組成 2.只能以字母或下劃線開頭 源 while true s input 變數名 if s exit print 歡迎下次使用 break if s 0 isalpha or s 0 for i in s 1 if not i.isalnum or...

字串練習題

輸入兩個字串,從第乙個字串中刪除第二個字串中所有的字元。例如,輸入 they are students.和 aeiou 則刪除之後的第乙個字串變成 thy r stdnts.s1 input 請輸入第乙個字串 s2 input 請輸入第二個字串 s3 方法一 for i in s1 print i,...