paulprayer

#写在前面的话:重点记录Python的特点

 Python特点:

1. 无分号断句

2. 不用担心溢出问题

 

3. if-else的用法不同

#if或else后面都要添加冒号:

import random
secret = random.randint(1,10)

print(\'-----我爱鱼C工作室-------\')
temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字(3次机会):")
guess = int(temp)
cnt = 1

if guess == secret:
    print("我靠,你是小甲鱼心里的蛔虫吗?!")
    print(\'哼,猜中了也没有奖励!\')
else:
        if guess > secret:
    #检查标点符号,英文的冒号
            print("哥,大了大了~~~")
        else:
            print("嘿,小了,小了~~~")
            
while guess != secret and cnt < 3:
    temp = input(" 不好意思,猜错了,重新输入吧:")
    guess = int(temp)
    cnt = cnt + 1
    if guess == secret:
        print("我靠,你是小甲鱼心里的蛔虫吗?!")
        print(\'哼,猜中了也没有奖励!\')
    else:
        if guess > secret:
    #检查标点符号,英文的冒号
            print("哥,大了")
        else:
            print("嘿,小了")
print("游戏结束,不玩啦^_^")
    

4.”与或非“直接用英文

与:and        (C++: &&)
或:or         (C++:||)
非:not        (C++: !)
def BooleanNOT(x):
    # not x
    if x:
        return False
    else:
        return True


def BooleanOR(x, y):
    # x or y
    if not x:
        return y
    else:
        return x

def BooleanAND(x, y):
    # x and y
    if not x:
        return x
    else:
        return y

5.留白

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2021-11-11
  • 2022-12-23
  • 2021-11-16
  • 2021-07-20
  • 2021-10-12
  • 2021-12-10
猜你喜欢
  • 2021-05-28
  • 2022-12-23
  • 2021-09-25
  • 2021-12-31
  • 2021-12-16
  • 2021-06-12
相关资源
相似解决方案