美文网首页Learn to Code
《笨办法学Python3》练习十四:提示和传值

《笨办法学Python3》练习十四:提示和传值

作者: 雨开Ame | 来源:发表于2019-03-01 21:26 被阅读0次

    练习代码

    from sys import argv
    
    script, user_name = argv
    prompt = '> '
    
    print(f"Hi {user_name}, I'm the {script} script.")
    print("I'd like to ask you a few questions.")
    print(f"Do you like me {user_name}?")
    likes = input(prompt)
    
    print(f"Where do you live {user_name}?")
    lives = input(prompt)
    
    print("What kind of computer do you have?")
    computer = input(prompt)
    
    print(f"""
    Alright, so you said {likes} about liking me.
    You live in {lives}. Not sure where that is.
    And you have a {computer} computer.    Nice.
    """)
    

    Study Drills

    1. Find out what the games Zork and Adventure were. Try to find copies and play them.

    在线 Zork 游戏(国内需翻墙)

    1. Change the prompt variable to something else entirely.

    2. Add another argument and use it in your script, the same way you did in the previous exercise with first, second = argv.

    3. Make sure you understand how I combined a """ style multiline string with the {} format
      activator as the last print.

    相关文章

      网友评论

        本文标题:《笨办法学Python3》练习十四:提示和传值

        本文链接:https://www.haomeiwen.com/subject/ixwjuqtx.html