python的不等号如下:
!= 不等于 - 比较两个对象是否不相等。
Python算术运算符:
以下假设变量: a=10,b=20:
+ 加 - 两个对象相加 a + b 输出结果 30。
- 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 -10。
* 乘 - 两个数相乘或是返回一个被重复若干次的字符串 a * b 输出结果 200。
/ 除 - x除以y b / a 输出结果 2。
% 取模 - 返回除法的余数 b % a 输出结果 0。
** 幂 - 返回x的y次幂 a**b 为10的20次方, 输出结果 100000000000000000000。
// 取整除 - 返回商的整数部分 9//2 输出结果 4 , 9.0//2.0 输出结果 4.0。
正确代码如下:
import random
secret = random.randint(1, 100)
guess = 0
tries = 0
print "AHOY! I'm the Dread Pirate Roberts, and I have a secret!"
print "It is a number from 1 to 99. I'll give you 6 tries."
while guess != secret and tries < 6:
guess = input("what's yer guess? ")
if guess < secret:
print "Too low, ye scurvy dog!"
elif guess > secret:
print "Too high, landlubber!"
tries = tries + 1
if guess == secret:
print "Avast! Ye got it! Found my secret, ye did!"
else:
print "NO more guesses! Better luck next time matey1"
print "The secret number was", secret
执行结果及你的错误原因如图: