zoukankan      html  css  js  c++  java
  • 003 Python与类C语言的区别(未完)

    #写在前面的话:重点记录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.留白

  • 相关阅读:
    队列 和 线程 之GCD dispatch
    ios NSUserDefaults存储数据(偏好设置)
    Binary Tree postorder Traversal
    Binary Tree Inorder Traversal
    Binary Tree Preorder Traversal
    Rotate List
    Reversed Linked List(Reverse a singly linked list)
    Remove Element
    Swap Nodes in Pairs
    Add Two Numbers
  • 原文地址:https://www.cnblogs.com/paulprayer/p/10366882.html
Copyright © 2011-2022 走看看