The the-the-the-Python Day 3

Source: Internet
Author: User

Today,i learned so much knowledge about the basis of Python.

Firstly, I studied methematical operators like ' + ', '/' and so on.

For instance,2*3=5, 4/2=2.0 and so on.

And, I also knew about comparison operators like ' > ', ' <= ', ' = = ' and the rest.

For exmple,2 < 3,2 <=3,3==3 and the rest.

Afterwards,i mastered assigning operators like ' = ', ' + = ', ' **= ' etc.

In the end of morning,i grasped the usage of logical operator,and, or, not.

Secondly,I knew a expression is a statement or code consisting of operands and operators, like 1 * 3 * 4 (1, 3, 4 St and for operand, * stand for operator), expressions can get value, so put them on the right of ' = ' to assign value to a VE Riable.

Thirdly, I mastered the usage of while loop, so I spent the whole afternoon going about doing it.

The first program I writed (what to get odd number and even number):

num = 1
While Num <= 100:
If num%2 = = 0:
Print (num)
num + = 1

and

num = 1

While Num <= 100:
If num%2! = 0:
Print (num)
num + = 1

A program of guessing age:

Age = 50

user_input_age = Int (input ("Age is:"))

While user_input_age! = Age:

if user_input_age = = Age:
Print ("Yes")
Elif user_input_age > Age:
Print ("bigger")
else:
Print ("smaller")
user_input_age = Int (input ("Age is:"))
Print ("End")

Or

Age = 51

Flag = True

While flag:
users_age = Int (Input ("is"))
if users_age = = Age:
Print ("Yes")
Flag = False
Elif users_age > Age:
Print ("bigger")
else:
Print ("smaller")
Print ("End")

or (and the usage of ' break ')

Age = 51

While True:
users_age = Int (Input ("is"))
if users_age = = Age:
Print ("Yes")
Break
Elif users_age > Age:
Print ("bigger")
else:
Print ("smaller")
Print ("End")

and

num = 1
While num<10:
Print (num)
num + = 1
if num = = 3:
Break

A program of using # to get a rectangle:

Num_height = 1
height = Int (input ("Please input the height of the Retangle:"))
width = Int (input ("Please input the width of the Retangle:"))

While num_height <= height:
Num_width = 1
While Num_width <= width:
Print ("#", end= "")
Num_width + = 1
Num_height + = 1
Print ()

A-to-get the multiplication table:

First = 1

While first <= 9:
Third = First
Second = 1
While second <= third:
Print (str (second) + "*" +str (third) + "=" +str (second*third), end= "\ T")
Second + = 1
Print ()
First + = 1

The the-the-the-Python Day 3

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.