วันอังคารที่ 16 สิงหาคม พ.ศ. 2559

Python

Odd Or Even
Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user. Hint: how does an even / odd number react differently when divided by 2?
code:
def setup():
    num = int(input("Please enter num:"))
    if num%2==0:
        print(num,"is even")
    else:
        print(num,"is odd")
setup()

Guessing Game One
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.

code:
import random
def setup():
    count=0
    number = random.randint(1,9)
    while True:
        num = int(input("Please guess num between 1-9:"))
        if num==number:
            print(num," is correct")
            print("your guess count is ",count)
            break
        else:
            count+=1
            if num>number:
                print("it's too high")
            else:
                print("it's too low")
setup()



ไม่มีความคิดเห็น:

แสดงความคิดเห็น

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...