实验目的
了解选择结构的含义,区分单一选项、双选项和多选项选择结构的不同和构造方法。
熟练使用关系运算符和逻辑运算符构造选择控制条件。
基于选择结构实践并掌握防御性编程和模块化编程的基本程序框架。
实验知识点:使用IDLE编写Python程序
If-Then, If-Then-Else,If-Then-Else-If以及Switch/Case语句的使用
关系运算符与逻辑运算符
Python相关语法
问题分析与程序设计
伪代码:
1.
Write “please enter a number”
Input number
If number>0
Write “positive”
Else if number<0
Write “negative”
Else
Write “zero”
2.
Declare earn As Float
Declare fax As Float
Input earn
If(earn>=0)AND(earn<50000)Then
Set fax=earn*0.05
Else If(earn>=50000)AND(earn<100000)Then
Set fax=2500+(earn-50000)*0.07
Else If earn>=100000 Then
Set fax=6000+(earn-100000)*0.09
Else
Write “fault”
End If
Write fax
3.
Declare year As Integer
Declare month As Integer
Declare sum As Integer
Input year,month,day
Select Case of month
Case 1
sum=0
Break
Case 2
sum=31
Break
Case 3
sum=59
Break
Case 4
sum=90
Break
Case 5
sum=120
Break
Case 6
sum=151
Break
Case 7
sum=181
Break
Case 8
sum=212
Break
Case 9
sum=243
Break
Case 10
sum=273
Case 11
sum=304
Case 12
sum=334
End Case
If(year%4==0)AND(month>2)Then
sum=sum+day+1
Else If year%4!=0
sum=sum+day
Else
sum=sum+day
End If
Write “year”+year+ “day”+sum
①打出十二个判断循环
②在每个循环中进行判断闰年
##code:
题目一、
number=eval(input("please enter a number"))
if number>0:
print("Positive")
elif number<0:
print("Negative")
else:
print("Zero")
题目二、
money=eval(input("please enter your money"))
if money>=0 and money<50000:
a=money*0.05
elif money>=50000 and money<100000:
a=2500+(money-50000)*0.07
elif money<0:
a=6000+(money-100000)*0.09
print("your tax",a)
题目三、
year=eval(input("please enter the year:"))
month=eval(input("please enter the month:"))
day=eval(input("please enter the day:"))
i=0
Days=0
if year%4==0 and year%100!=0:
day[2]=29
while i
Days=Days+Days[i]
i=i+1
print("day",Days+day,"year",year)
#实现过程与测试结果分析
过程较为复杂但是运算结果正确
#实验结果总结
实验完成较好
#创新部分和对实验的意见与建议
明白了选择结构,继续努力。