Python Study Notes

Source: Internet
Author: User

Use the function to get user input

(A) Create a script and use the built-in function to obtain a string from the user input, and then display the string that the user just entered.

(B) Add a similarCodeBut this time it is a value, convert it to a value and display it to the user.

 
# Araw_input ("enter something") # B A = raw_input ("Enter some number") print (INT ())

Loop and number

(A) Write a loop with while and output 0 to 10

(B) Use the range function for the same event.

# AA = 0 while a 

determines whether the value entered by the user is positive or negative or zero.

 I = int (raw_input ('enter some number ')) if I> 0: print 'you input a positive number 'elif I 

to get a string from the user, print it out by character

 STR = raw_input ('enter some string ') while STR: Print STR [0] STR = STR [1:] # Or STR = raw_input ('en TER some string') for I in STR: print I 

enter five values and use sum.

 I = ret = 0 while I 

obtain the five values and calculate their average value

 ret = 0for I in range (5): Str = raw_input ('enter some number'); ret = RET + float (STR) print RET/5 

Use raw_input to prompt the user to enter a value ranging from 1 to. If yes, the system displays and exits, otherwise, you will be prompted to enter

 loop = 1 while loop: Str = raw_input ('enter 0 ~ A value between 100 '); STR = int (STR) If 0 

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.