ITS100

Lab
2
–
Basic element of Python programming #1
Page
1
Sirindhorn International Institute of Technology
ITS100: Computer and Programming
Laboratory
Basic element of
Python programming
#1
Lab
2
Objective:
Understand how to
get input from users and store data
Understand the concept of variables
Understand how to perform arithmetic operations in
python
Understand how to use library functions, e.g., mathematical functions
Try these commands:
List of basic mathematical functions
The result is ……………..
ITS100

Lab
2
–
Basic element of Python programming #1
Page
2
Ex
ample
:
A
program to convert your height from centimeters to meters. This program takes an
input from
user and then shows the result.
Exercise 1:
Input 3
number
and print them out in reverse order
.
Exercise
2
:
Write a program that takes two integer numbers and prints out the product
(multiplication) of the first and the second
numbers. The program output should look like this:
Exercise
3
:
Write a program that converts a volume in milliliter
to fluid ounce (1 milliliter =
0.034 ounces).
The program output should look like this:
Enter a volume (in ml):
250
Volume in milliliter is
250.00
Volume in ounce is 8.50
Enter the first
integer
number:
20
Enter the second
integer
number:
5
20*5 = 100
Enter the first number:
1
Enter the second number:
2
Enter the third number:
3
Reverse order of 1 2 3

> 3 2 1
ITS100

Lab
2
–
Basic element of Python programming #1
Page
3
Exercise 4:
Write the following boolean expressions in Python
2 is greater than 1
2 is greater than 1 but smaller than 3
either 2 is greater than
1, or 1 is greater than 2
2 is not equal 1 (hint: equality operator in Python is ==, while negation is not )
Exercise
5
:
Write a program that converts a temperature in Celsius (C) to Fahrenheit (F). The
program output should look like this:
Note
Exercise
6
:
Write a program which receives three numbers a, b, c fr
om user, and prints out the
area
of triangle with edges a, b, c.
Hi
n
t:
√
(
)
(
)
(
)
where
Exercise
7
:
Write a program to take
s
two integer numbers as
input data and display their sum,
difference, product (multiplication), and quotient. The program
output should look like this:
Enter
a
b c
:
3
5
4
The
a
rea
is
6.
0
Enter the first
integer
number:
8
Enter the second
integer
number:
22
The sum is 30
The difference is

14
The product is 176
The quotient is 0
Enter a temperature in C:
37
Temperature in C = 37.00
Temperature in F = 98.60
ITS100

Lab
2
–
Basic element of Python programming #1
Page
4
Exercise
8
:
Write a p
rogram that responses as follow
What is your family name? Bush
What is your given name? George Walker
I will call you GB for short.
Hint: 'Bush'[0] = B and 'George Walker'[0]=G
Exercise
9
:
Write a pro
gram that receives a three

digit integer from the user, then print out the
sum
of all these three digits. Your program should response as follows
:
Exercise
10
:
Write a program to calculate


where x and y can be any real numbers.
The program output should look like this:
Exercise
11
:
Write a program to draw a circle
.
The program should look like this:
Enter a value for x:
3.0
Enter a value for y:
5.0
The result is 22.
Enter the radius of circle
:
1
00
E
nter the
color (red, blue, green
)
:
blue
x=123
sum of digit = 6
ITS100

Lab
2
–
Basic element of Python programming #1
Page
5
Exercise 12:
Asks the positions (x,y) and radius of two circles from user. Draws this two circle
and draws the
middle
point
between them.
(Use Turtle Module)
Enter the radius of circle:
50
Enter the position of circle 1 [x y]:

50 0
Enter the position of circle 2 [x y]:
100 150
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment