A small interactive script

Source: Internet
Author: User

Follow the stupid method of Python, and learn python for a few days, and you want to show off.

According to the textbook hit the code, barely enough to calculate a program it. The script is the. py file we wrote!

Formally cut into the theme

>>>#-*-coding:utf-8-*- #声明这是utf编码! Prevent garbled!

>>>os_char = ' GB18030 '

>>>from sys import argv #从sys模块导入argv (parametric variable)

>>>script, user_name = argv #把argv的参数分给script和user_name, this process is called unpack (unpacking)

>>>prompt = ">" #在提示 > enter the data you want!

>>>print "Hi%s, I ' m ' the%s script."% (user_name, script)

>>>print "%s, do you like me?" ". Encode (Os_char)% user_name #%s,%r,%d is the format Control tool that tells Python to put the value on the right side into the position of the left%s!

>>>A1 = Raw_input (Prompt) #raw_input () raw input

>>>print, who is your goddess? ", Encode (Os_char)

>>>A2 = Raw_input (Prompt)

>>>print "What's your favorite person?" ". Encode (Os_char)

>>>A3 = Raw_input (Prompt)

>>>print "" "

Now, according my gatherations, you said '%s ' to Me,and

Your Said:your Goddess "%s", your favorate People is "%s".

"" "% (A1, A2, A3)

You can enter the above code in the editor sublime Text2, or in Notepad (win+r input notepad).

Then save the suffix as a. py. The parameter variable (Argument variable) mentioned above is a standard programming term that guarantees

Save the parameters you passed to it when you ran the Python script (Argument)!

A small interactive script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.