0% found this document useful (0 votes)
20 views

Learning-Python-Programming - Copy

kk

Uploaded by

Aung Myint Tun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Learning-Python-Programming - Copy

kk

Uploaded by

Aung Myint Tun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Learning Python

Programming
Part-1
Installation

 Download Python | Python.org


 Visual Studio Code - Code Editing. Redefined
Path
Cont’d
Python

 The python programming language has a wide range of syntactical constructions,


standard library function and interactive development environment features.
Data type
Operators
Storing values in variables

 Assignment Statements 42
 Test=42

Test
Variables

 Spam=‘Hello’
 Spam=‘Goodbye’
Variables Name

Variable names are


case-sensitive,
meaning
that spam, SPAM, Spam,
and sPaM are four
different variables.
String Concatenation and
Replication

 Valid Structure
 ‘Hello’+’Python’
 ‘Hello’*5
 Invalid Structure
 ‘Hello’+2
print(), input(), len() function

 print(‘hello’)
 print (‘What is your name’)
 name=input()
 print(‘Hello’+name)
 print (len(name))
The str(), int(), and float()
Functions

 For type conversion process, use str(), int() and float() function
 a=20
 b=str(a)
 c= int(b)
 d=float(c)
Example-1

print('What is your age?') # ask for their age


myAge = input()
print('You will be ' + str(int(myAge) + 1) + ' in a year.')
Exercise-1
 Which of the following are operators, and which are values?
 *, ‘python’,-88, 23.0, /, %, ‘-90’
 What does the variable testing contain after the following code
runs?
 testing = 20
testing+ 1
 What is the output of the following codes?
 a=23, b=34, c=65
 d=(c-b)*a
 The following are correct sentence or not
 Print(“testing python”+23+’Program’)
Boolean Value and Boolean
operator

 Values
 True, False
 Operator
 And, or, not
Comparison Operator
MIXING BOOLEAN AND
COMPARISON OPERATORS

(4 < 5) and (5 < 6)


True
(4 < 5) and (9 < 6)
False
(1 == 2) or (2 == 2)
True
Flow control statement

 if statement
 else statement
 elif statement
Example-2

 name = ‘python'
sentence = 300
if name == ‘python':
print(‘Welcome from python.')
elif sentence< 12:
print(‘sentence is less than 300')
elif sentence > 2000:
print(‘sentence is greater than 300')
elif sentence ==300:
print(‘sentence is 300')
while loop statement

 data= 0
name = ''
while name != '':
while data < 5:
print('Please type your
print(‘welcome from pythonn') name.')
data = data + 1 name = input()
print('Thank you!')
break statement

 while True:
 print('Please type your name.')
 name = input()
 if name == 'your name':
 break
 print('Thank you!')
Example-3
 while True:
 print('Who are you?')
 name = input()
 if name != ‘python':
 continue
 print('Hello, python. What is the password? (It is a fish.)')
 password = input()
 if password == ‘1234567':
 break
 print('Access granted.')
The starting, stopping and stepping
Arguements to range()

 for i in range(12, 16):


print(i)

 for i in range(0, 10, 2):


print(i)

 for i in range(5, -1, -1):


print(i)
Importing Module

 modules called the standard library


• The import keyword
• The name of the module
• Optionally, more module names, as long as they are separated by commas
Random Module

 import random
 for i in range(5):
 print(random.randint(1, 10))
Random.choice()

 import random
 name='HelloTesting'
 char = random.choice(name)
 print("random char is ", char)
random.uniform()

 import random
 num1 = random.random()
 print("First Random float is ", num1)
 num2 = random.uniform(9.5, 99.5)
 print("Second Random float is ", num2)
 num3 = num1 * num2
 print("Multiplication is ", num3)
ENDING A PROGRAM EARLY WITH
THE SYS.EXIT() FUNCTION

 import sys

while True:
print('Type exit to exit.')
response = input()
if response == 'exit':
sys.exit()
print('You typed ' + response + '.')
Guess Number Game
create a simple rock, paper, scissors
game

You might also like