如果想解题就需要认识python中三元表达式的一些语法:
在其他语言当中,例如c++中三元表达式:
#include//导入iostream using namespace std;//命名空间 int main() { int a,b; cin >> a >> b; cout<< ((a>b)? a:b); return 0; }
不过 python中没有其他语言中的三元表达式,不过有类似的实现方法:
# -*- coding: utf-8 -*-
#一个判断哪个数大的程序
#1.输入:
try:
a = int(input('a:'))
b = int(input('b:'))
except:
print('输入错误')
#2.三元表达式:
big = a if a>b else b
print(big)
输出结果:
# -*- coding: utf-8 -*-
# 三元表达式
def judge(num):
return '及格' if num >= 60 else '不及格'
#定义变量
scs = []
out_scs = {}
for i in range(0,12):
#输入
scs.append(int(input('num:')))
#处理
out_scs[scs[i]] = judge(scs[i])
#输出
print(out_scs)
运行结果:



