Python Chapter 2 homework, python Chapter 2 homework

Source: Internet
Author: User
Tags mathematical functions

Python Chapter 2 homework, python Chapter 2 homework

2-1 simple information:

message="hello world"print(message)

Running result:


2-2 multiple simple messages:

message="hello world"print(message)message="no thanks"print(message)

Running result:


2-3 personalized information:

name="Ro bo"print("hello, "+name+", Good morning!")

Running result:


2-4 adjust the name case:

name="Ro bo"print("hello, "+name.lower()+", Good morning!")print("hello, "+name.upper()+", Good morning!")print("hello, "+name.title()+", Good morning!")

Running result:


2-5 famous saying:

print('Dresser said:"The ideal is the sun of life."')

Running result:


2-6 famous saying 2:

famous_person="Dresser"message='"The ideal is the sun of life."'print(famous_person+" said: "+message)

Running result:


2-7 remove white spaces in person names:

famous_person="\nDresser\t"print("origin:")print(famous_person)print("lstrip")print(famous_person.lstrip())print("rstrip")print(famous_person.rstrip())print("strip")print(famous_person.strip())

Running result:


2-8 digits 8:

 
print(4+4)print(9-1)print(2*4)print(int(16/2))

Running result:



2-9 favorite numbers:

number=8print("My favourite number is "+str(number)+"!")

Running result:


2-10 Add comments:

# Each element in the list is the 3rd power of value. arr = [value ** 3 for value in range ()] print (arr)
# Some mathematical functions arr = [] for item in range (): arr. append (item) print (arr) print (min (arr) # minimum value print (max (arr) # maximum value print (sum (arr) # sum

2-11 zen about Python:

Running result:





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.