问一个python编程片段

来源:百度知道 编辑:UC知道 时间:2024/09/22 14:52:42
Given the variables name1 and name2 , write a fragment of code that assigns the larger of their associated values to first .
这里的larger说的是在字母表里那种,比如mouse比apple大因为mouse在字母表上在apple后面
谢谢啦

# 读入 name1 和name2 的值(如你所说,是两个字符串)
name1 = raw_input('Please Input Name 1:')
name2 = raw_input('Please Input Name 2:')

# 将在字母表中靠后的字串赋给变量 first (此处用的and or 的一个用法)
first = name1 > name2 and name1 or name2

# 输出 first
pring first