Python比较两个数的大小
2017-10-29 21:17
316 查看
目标:比较两个数大小,如果num1大于num2,则输出num1>num2,否则将输出2
import random
def compareNum(num1,num2):
if(num1 > num2):
return str(num1)+">"+str(num2)
else:
return 2
num1 = random.randrange(1,5)
num2 = random.randrange(1,3)
input ("num1 = "), num1
input ("num2 = "), num2
print (compareNum(num1,num2))
过程中容易出现的问题和解决方法:
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 7
num1 = 4
^
1、TabError: inconsistent use of tabs and spaces in indentation
直接定义值的方式不正确
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 11
print compareNum
^
2、IndentationError: unexpected indent
该行缩进不正确
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 11
print compareNum
^
3、SyntaxError: Missing parentheses in call to 'print'. Did you mean print(compareN
um)?
Print后面没有加括号
import random
def compareNum(num1,num2):
if(num1 > num2):
return str(num1)+">"+str(num2)
else:
return 2
num1 = random.randrange(1,5)
num2 = random.randrange(1,3)
input ("num1 = "), num1
input ("num2 = "), num2
print (compareNum(num1,num2))
过程中容易出现的问题和解决方法:
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 7
num1 = 4
^
1、TabError: inconsistent use of tabs and spaces in indentation
直接定义值的方式不正确
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 11
print compareNum
^
2、IndentationError: unexpected indent
该行缩进不正确
C:\Users\tl>python C:\Users\tl\Desktop\test.py
File "C:\Users\tl\Desktop\test.py", line 11
print compareNum
^
3、SyntaxError: Missing parentheses in call to 'print'. Did you mean print(compareN
um)?
Print后面没有加括号
相关文章推荐
- 请定义一个宏,比较两个数的a、b的大小,不能使用大于、小于、if语句
- 2.7节 10.1 指针比较两个数大小
- 15电气郄慧敏vb作业6比较两个数的大小
- 输入两个数,比较大小
- 比较大小两个数的
- 位运算之不使用任何比较判断比较两个数大小问题
- 比较两个数的大小
- C++ 不用判断运算符进行比较两个数的大小
- 08-14 比较两个数的大小,不用判断语句
- Python 不同对象比较大小示例探讨
- 比较两个数的大小
- 比较两个数的大小
- python 分支结构 比较大小
- 比较两个数的大小
- 比较两个数的大小,自定义比较两个整数的大小的方法
- 使用C语言编写程序,求两个整数的较大值(随机输入两个数,比较大小)
- vb比较两个数的大小
- 不用比较判断两个数大小
- python中用cmp比较字典大小
- 每日一题:编写一个函数,不使用算术运算符,实现比较两个数的大小