Python第四章作业(初级) (educoder.net)
- def print_hi_human(): # 函数名用小写字母
-
- print("人类,你好!")
-
- if __name__ == '__main__':
- print_hi_human()
- def say_hi_human(): # 函数名用小写字母
- return "人类,你好!"
-
- if __name__ == '__main__':
- char = say_hi_human()
- print(char)
- def say_hi_person(full_name): # 函数名用小写字母,函数名填空
- char = full_name + ",你好!"
- return char
- if __name__ == '__main__':
- # 函数名作为print()函数的参数,输出say_hi_human()的返回值。输入的人名作为函数的参数
- person_name = input()
- char = say_hi_person(person_name)
- print(char)
- def say_hi_gender(full_name, gender):
- if(gender == '男'):
- print('尊敬的{}先生,欢迎来到火星!'.format(name))
- elif(gender == '女'):
- print('尊敬的{}女士,欢迎来到火星!'.format(name))
- else:
- print('尊敬的{}先生/女士,欢迎来到火星!'.format(name))
-
-
-
- if __name__ == '__main__':
- name = str(input())
- gender = str(input())
- say_hi_gender(name, gender)
- def say_hi_multi_parameter(*name): # 括号里填上参数
- for i in name:
- print('{},你好!'.format(i))
-
-
- say_hi_multi_parameter('孟浩然')
- say_hi_multi_parameter('杜甫', '李白', '柳宗元', '李商隐')
- x = float(input())
- y = float(input())
- num = pow(x,y)
- print(x**y)
- def fabs(x):
- """返回x的绝对值"""
- # 补充你的代码
- return abs(x)
-
- if __name__ == '__main__':
- n = float(input())
- print(fabs(n))
- def Car(year,type1,a = "宝马"): # 括号里补充你的代码
- a = '这是一辆{:}年生产,型号是{:}的{:}牌汽车。'.format(year,type1,a)
- return a
-
- # 以下内容不要修改
- ls = input().split() # 根据空格切分输入字符串为列表
- print(Car(*ls)) # 调用函数,取列表中的全部数据做参数
- def sefDivisor(n):
- if '0' in str(n):
- return False
- for i in str(n):
- if n % int(i) != 0:
- return False
- else:
- return True
-
-
- n = int(input())
- for m in range(1,n+1):
- if sefDivisor(m):
- print(m,end = ' ')
- def sqrt_binary(x,g):
- low = 0
- high = x + 0.25
- m = (low + high) / 2
- while abs(m ** 2 - x) > g:
- if m ** 2 < x:
- low = m
- else:
- high = m
- m = (low + high) / 2
- print(f'{m:.8f}')
- print(f'{sqrt(x):.8f}')
-
- from math import sqrt
- x, g = input().split(',')
- sqrt_binary(float(x), float(g))