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

Practice Week 5 - Python

math

Uploaded by

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

Practice Week 5 - Python

math

Uploaded by

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

Automatically generated by Colaboratory.

References:
1. https://www.w3schools.com/python/default.asp
2. https://towardsdatascience.com/downloading-datasets-into-google-drive-via-google-colab-
bcb1b30b0166
3. https://docs.python.org/3/library/csv.html
4. https://matplotlib.org/3.1.1/tutorials/introductory/sample_plots.html

1. Print a text message


print("Hello USTH!")

"""1.1. Get input from user and print it out"""

x = input()
print('x = ', x)

2. Do simple calculation:
a=1
b=2
c=a+b
print("Sum of ", a, " and ", b, " equal ", c)

2.1. Get value of a and b from user input and calculate their sum
a = int(input())
b = int(input())
c=a+b
print("Sum of ", a, " and ", b, " equal ", c)
3. If ... else:
a=1
b=2
if a > b:
print(a, " is greater than", b)
elif a == b:
print(a, " is equal ", b)
else:
print(a, " is smaller than", b)

4. For... loop

n = 10
total = 0
for i in range(1, n+1):
total = total + i
print("Sum of integer numbers from 1 to ", n, " is ", total)

5. While ...loop
n = 10
total = 0
i=1
while i <= n:
total = total + i
i=i+1
print("Sum of integer numbers from 1 to ", n, " is ", total)
Reference:
User input: https://www.w3schools.com/python/python_user_input.asp
String:https://www.w3schools.com/python/python_strings.asp

1. Input one positive integer A from the keyboard, print all the numbers from A to 1 in two way: (1)
using for-loop and (2) using while-loop. All the numbers should be printed on a same line, separated
by “, ”.
Example:
Input: 5
Output: 5, 4, 3, 2, 1
2. Input a non-negative interger A from the keyboard, print all the even numbers from 0 to A (including
0 and A).
3. Input a non-negative interger A from the keyboard, compute the factorial A!.
4. Input one positive integer A from the keyboard, check if 5<=A<=10, if it’s true then print A, else
input the number A again.
Note that the input procedure should be repeated until the conditions are satisfied.
5. Input one positive integer A from the keyboard (0<A<10), print the multiplication table of A.
6. Input three positive integers a, b, c. Check whether a, b, c are the lengths of three sides of a triangle
or not. If true, output the triangle type. It is required to consider only simple cases of triangle:
isosceles, equilateral, square, normal.
7. Input three positive integers a, b, c, print the largest number out of those 3 numbers.
8. Input two positive integers a and b. Check for the following conditions:
- If a=b, print the message that two numbers are equal.
- If a<b, print the numbers from a to b (including a and b).
- If a>b, print the numbers from b to a (including a and b).
9. Input a 3-digit positive integer and output its English word representation.
Example:
Input: 423
Output: Four hundred twenty three
10. Input a string from the keyboard. Do the following operations:
− Print the length of input string.
− Change the string to uppercase format.
− Change the string to lowercase format.
− Print the 2nd character of the string.
− Insert the string "IN" between the first character and the second character of the string.
− Check if the letter "s" is in the string.

You might also like