【Python 基础 2022 最新】练习 2
【摘要】
【Python 基础 2022 最新】练习 2
概述第五题第六题第七题第八题第五题 (答案)第六题 (答案)第七题 (答案)第八题 (答案)
概述
从今天开始, 小白我将带领大家学习一下 ...
概述
从今天开始, 小白我将带领大家学习一下 Python 零基础入门的内容. 本专栏会以讲解 + 练习的模式, 带领大家熟悉 Python 的语法, 应用, 以及代码的基础逻辑.
第五题
def assignment():
# a. assign x the value 8
# b. assign both x and y the value 9 in one line of code
# c. assign x the value 10 and y the value 12 using one line of code
# d.
# run the program
assignment()
预期输出:
8
9 9
10 12
7
第六题
def even_odd(x):
# your code
# define some sample data
a=45
# run the program
even_odd(a)
预期输出:
odd
第七题
def check_max(lst):
# your code
# define some sample values
nums=[3, 41, 12, 9, 74, 15]
# run the program
check_max(nums)
预期结果:
74
第八题
# your code
check_balance(1000,1400)
check_balance(1000,800)
check_balance(1000,1200)
预期输出:
your account balance has increased by $ 400
your account balance has decreased by $ 200
No action is required at this time
第五题 (答案)
def assignment():
# a. assign x the value 8
x=8
print(x)
# b. assign both x and y the value 9 in one line of code
x=y=9
print(x,y)
# c. assign x the value 10 and y the value 12 using one line of code
x,y=10,12
print(x,y)
# d.
x=4
x+=1
x+=1
x+=1
print(x)
# run the program
assignment()
第六题 (答案)
def even_odd(x):
# your code
if x%2==0:
print('even')
else:
print('odd')
# define some sample data
a=45
# run the program
even_odd(a)
第七题 (答案)
def check_max(lst):
# your code
Max_num = None
for num in lst:
if (Max_num is None or num > Max_num):
Max_num = num
print(Max_num)
# define some sample values
nums=[3, 41, 12, 9, 74, 15]
# run the program
check_max(nums)
第八题 (答案)
# your code
def check_balance(num1, num2):
# 判断
if (num2 > num1 * 1.25):
print("your account balance has increased by $", num2 - num1)
elif (num2 < num1 * 0.98):
print("your account balance has decreased by $", num1 - num2)
else:
print("No action is required at this time")
# 调用
check_balance(1000,1400)
check_balance(1000,800)
check_balance(1000,1200)
输出结果:
your account balance has increased by $ 400
your account balance has decreased by $ 200
No action is required at this time
文章来源: iamarookie.blog.csdn.net,作者:我是小白呀,版权归原作者所有,如需转载,请联系作者。
原文链接:iamarookie.blog.csdn.net/article/details/125342060
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)