Python系列-比较两个数的大小
来源:互联网 发布:杀人软件 编辑:程序博客网 时间:2024/06/05 16:41
目标:比较两个数大小,如果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后面没有加括号
- Python系列-比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 两个数大小的比较
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 两个数大小的比较
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- 比较两个数的大小
- Git系列-常见命令和用法
- 矩形滑雪场(深度搜索)
- Git系列-环境搭建
- 开发第一个SPringMVC的程序
- tensorflow实现softmax regression识别手写数字
- Python系列-比较两个数的大小
- Java高级篇-6-数组拷贝方法
- get和post请求区别
- [贪心+堆+链表] 51Nod1053 最大M子段和 V2
- [练习][洛谷2700]Kruskal 逐个击破
- Leetcode: 322. Coin Change(Week8, Medium)
- listview and arrayadapter
- 【weekly-sharing】BM算法(Boyer-Moore算法)学习记录
- “千里眼”“顺风耳” 铁路依靠科技创新实现安全管理现代化