程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python foundation 2022 latest] exercise 2

編輯:Python

【Python Basics 2022 newest 】 practice 2

  • summary
  • Fifth question
  • Sixth question
  • Question seven
  • The eighth question
  • Fifth question ( answer )
  • Sixth question ( answer )
  • Question seven ( answer )
  • The eighth question ( answer )

summary

Starting today , Xiaobai, I will lead you to learn Python Introduction to zero foundation . This column will explain + Practice mode , Let's get familiar with it Python The grammar of , application , And the basic logic of the code .

Fifth question

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()

Expected output :

8
9 9
10 12
7

Sixth question

def even_odd(x):
# your code
# define some sample data
a=45
# run the program
even_odd(a)

Expected output :

odd

Question seven

def check_max(lst):
# your code
# define some sample values
nums=[3, 41, 12, 9, 74, 15]
# run the program
check_max(nums)

Expected results :

74

The eighth question

# your code
check_balance(1000,1400)
check_balance(1000,800)
check_balance(1000,1200)

Expected output :

your account balance has increased by $ 400
your account balance has decreased by $ 200
No action is required at this time

Fifth question ( answer )

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()

Sixth question ( answer )

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)

Question seven ( answer )

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)

The eighth question ( answer )

# your code
def check_balance(num1, num2):
# Judge
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")
# call
check_balance(1000,1400)
check_balance(1000,800)
check_balance(1000,1200)

Output results :

your account balance has increased by $ 400
your account balance has decreased by $ 200
No action is required at this time

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved