This commit is contained in:
张壹 2025-05-26 06:49:34 +08:00
parent e030d195b8
commit 88c8f2ca32
11 changed files with 19 additions and 11 deletions

View File

@ -1,3 +1,4 @@
bill_price = int(input('Please enter bill total price : '))
number_of_diners = int(input('Please enter diners number : '))
# round(数值, 小数点位数)
print('the price for each person is {0}'.format(round(bill_price/number_of_diners,2)))

View File

@ -1,4 +1,5 @@
large = int(input('enter number over than 100 : '))
small = int(input('enter number smaller than 10 : '))
# // floor division 相当于c中的floor函数
answer = large//small
print('{0} goes into {1} for {2} times'.format(small, large, answer))

View File

@ -1,9 +1,7 @@
color = str(input('Enter you favourite colour : '))
if color == 'red':
print('I like red too')
elif color == 'RED':
print('I like red too')
elif color == 'Red':
Color = color.capitalize()
if Color == 'Red':
print('I like red too')
else:
print('I don\'t like {0}, I prefer red'.format(color))

View File

@ -1,2 +1,3 @@
name = str(input('enter your name to check length : '))
# len()不止能够计算str的长度 它可以返回所有容器的长度
print('{0} name length is {1}'.format(name, len(name)))

View File

@ -1,4 +1,5 @@
first_name = str(input('Enter your first name in lower-case : '))
surname = str(input('Enter your surname in lower-case : '))
# title就是把word转换为标题形式
compact = first_name.title() + ' ' + surname.title()
print(compact)

View File

@ -1,4 +1,5 @@
rhyme = str(input('Enter the 1st. line of nursery rhyme : '))
start = int(input('Enter start number for display : '))
end = int(input('Enter end number for display : '))
# 截断字符串包含start位不包含end位
print('this is the 1st. line \n {0} \n and this is truncated {1}'.format(rhyme, rhyme[start:end]))

View File

@ -1,3 +1,3 @@
number = float(input('Enter number with lots of decimal number : '))
print(round(number*2, 2))
#print(round(number*2, 2))
print(round(number*2))

View File

@ -1,4 +1,5 @@
import math
number = int(input('Enter number over 500 : '))
print(round(math.sqrt(number)))
#print(round(math.sqrt(number)))
print(round(math.sqrt(number), 2))

View File

@ -1,3 +1,3 @@
import math
print(round(math.pi, 5))
dig = int(input("how many digits you want: "))
print(round(math.pi, dig))

View File

@ -1,5 +1,6 @@
import math
radius = float(input('Enter circle radius : '))
# ** 表示幂计算
area = math.pi * (radius**2)
print(area)

View File

@ -1,4 +1,7 @@
compnum = 50
import numpy as np
compnum = np.random.randint(1, 100)
count = 0
number = int(input('Enter number to guess : '))
while number != compnum: