GithubHelp home page GithubHelp logo

Python 練習題(p.48-4) about python HOT 5 OPEN

jerrywu2013 avatar jerrywu2013 commented on July 23, 2024
Python 練習題(p.48-4)

from python.

Comments (5)

xiaoyoru avatar xiaoyoru commented on July 23, 2024

學號:B10309022
姓名:蕭羽汝

程式內容:

import random
article = ['the', 'a', 'another']
subject = ['boy', 'girl', 'woman', 'man', 'cat', 'dog', 'fox', 'horse']
verb = ['hoped', 'jumped', 'laughed', 'kicked', 'climbed']
adverb = ['loudly', 'quietly', 'well', 'badly', 'proudly', 'angrily', 'happily']

time = input('Please input a number(1-10) or use the default 5:')
times = 5
sentence1 = ''
sentence2 = ''
if time != "":
    times = int(time)
else:
    times = 5

while times > 0:
    sentence1 = ''
    i = random.choice(article)
    sentence1 += ' '+ i 
    i = random.choice(subject)
    sentence1 += ' '+ i
    i = random.choice(verb)
    sentence1 += ' '+ i
    i = random.choice(adverb)
    sentence1 += ' '+ i

    sentence2 = ''
    i = random.choice(article)
    sentence2 += ' '+ i 
    i = random.choice(subject)
    sentence2 += ' '+ i
    i = random.choice(verb)
    sentence2 += ' '+ i 
    print(random.choice([sentence1, sentence2]))
    times -= 1

from python.

arthur55 avatar arthur55 commented on July 23, 2024

B10309020 張書銘

article = ["the","a","another","other"]
subject = ["cat","dog","man","woman","teacher","student"]
adverb = ["loudly","quietly","well","badly"]
verb = ["fight","run","jump","fall","fly"]
import random
m = input ("Enter a number in range 1 to 10 or use default 5\n")
if m == "" :
    m = 5  
else : 
    m = int (m)
if m <= 10 and m >=1 :
    for i in range(m):  
        x = random.choice(article)+" "+random.choice(subject)+" "+random.choice(verb)+" "+random.choice(adverb)
        y = random.choice(article)+" "+random.choice(subject)+" "+random.choice(verb)
        print (random.choice([x,y]))
else:
    print ("The number is not in range 1 to 10.")

from python.

cindy24678 avatar cindy24678 commented on July 23, 2024

B10309024 陳穎婷

import random

article = ["the", "a"]
subject = ["cat", "dog", "man", "woman"]
verb = ["laughed", "jumped", "hoped"]
adverb = ["loudly", "quietly", "well", "badly"]
t = 0
n = int(input("please enter an integer(1~10)"))

while True:
    try:
        if 0 <= n <= 10:
            line =""
            line = line + " " + random.choice(article)
            line = line + " " + random.choice(subject)
            line = line + " " + random.choice(verb)
            t = t + 1
            c = random.randint(1,2)
            if c == 1:
                line = line + " " + random.choice(adverb)
            print(line)
            if t == n: break
        else:
            n = int(input("please enter an integer(1~10)"))
    except ValueError as err:
        print(err)

from python.

MeiSee avatar MeiSee commented on July 23, 2024

張美詩 B10309008

import random
article = ["那個","這個","一個","這些"]
subject = ["超人","殺手","屍體","小偷","鹹魚","恐龍","帥哥","小明","明星","淑女"]
verb = ["大笑","竊笑","傻笑","奸笑","譏笑","狂笑","微笑","不笑","開槍","殺人","大便","瘙癢","泡妞","撒尿","中槍","握手","喝茶"]
adverb = ["忽然","悄悄","大聲","粗魯","公然","連忙","默默","索性","僅僅"]

x = 0
while True:
    x = input("\n輸入1至10範圍內的數字或使用默認值:\n")
    if x == "":
        x = 5
    else:
         x = int(x)

    if x < 0 or x > 10:
        print ("輸入錯誤。請重新輸入!")
        continue

    else:
        for i in range(x):
            if random.randint(1,2)==1:
                print (random.choice(article)+" "+random.choice(subject)+" "+random.choice(adverb)+" "+random.choice(verb))

            else:
                print (random.choice(article)+" "+random.choice(subject)+" "+random.choice(verb))

from python.

wai-imyen avatar wai-imyen commented on July 23, 2024

B10330331 陳語晏

#奇怪的詩(進階)
import random
article = ["the","a",]
subject = ["cat","dog","man","woman"]
adverb = ['loudly','quietly','well','badly']
verb = ['ran','jumped','laughed','slept','thought']


while True:
    x = input('請輸入指定句數or直接鍵入Enter:')
    if x is not "":
        y = int(x)

        if y > 10 or y < 0:
            print('請輸入10句以內')

        else:
            for i in range(y):
                a = random.choice(article)+" "+random.choice(subject)+" "+random.choice(adverb)+" "+random.choice(verb)
                b = random.choice(article)+" "+random.choice(subject)+" "+random.choice(verb)
                c = [a,b]
                print(random.choice(c))

            break

    else:
        for i in range(5):
            a = random.choice(article)+" "+random.choice(subject)+" "+random.choice(adverb)+" "+random.choice(verb)
            b = random.choice(article)+" "+random.choice(subject)+" "+random.choice(verb)
            c = [a,b]
            print(random.choice(c))
        break

from python.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.