Python Assignment 1
1. Write Python code that prints your name, student number and email address.
An example runs of the program:
Bob
ST1001
bob@gmail.com
Ans:
print("Ajo")
print("754878")
print("ajo024@pm.me")
2. Write Python code that prints your name, student number and email address using escape
sequences.
An example runs of the program:
Bob
ST1001
bob@gmail.com
Ans:
name= "Ajo"
student_number= "748487"
email= ajo024@pm.me
print(name+ "\n"+ student_number+ "\n"+email)
3. Write Python code that add, subtract, multiply and divide the two numbers. You can use
the two numbers 14 and 7. An example run of the program:
14 + 7 = 21
14 * 7 = 98
14 – 7 = 7
14 / 7 = 2
Ans:
a=14
b=7
a+b
a-b
a*b
a/b
4. Write Python code that displays the numbers from 1 to 5 as steps.
An example runs of the program:
1
2
3
4
5
Ans:
for i in range(1,6):
print(i)
5. Write Python code that outputs the following sentence (including the quotation marks and
line break) to the screen:
An example runs of the program:
"SDK" stands for "Software Development Kit", whereas
"IDE" stands for "Integrated Development Environment".
Ans:
sentence = "\"SDK\" stands for \"Software Development Kit\", whereas\n\"IDE\" stands for
\"Integrated Development Environment\""
print(sentence)
6. Practice and check the output
print("python is an \"awesome\" language.")
print("python\n\t2023")
print('I\'m from Entri.\b')
print("\65")
print("\x65")
print("Entri", "2023", sep="\n")
print("Entri", "2023", sep="\b")
print("Entri", "2023", sep="*", end="\b\b\b\b")
Ans:
python is an "awesome" language.
python
2023
I'm from Entri
Entri
2023
Entr2023
Entri*20
7. Define the variables below. Print the types of each variable. What is the sum of your
variables? (Hint: use a type conversion function.) What datatype is the sum?
num=23
textnum="57"
decimal=98.3
Ans:
num = 23
textnum = "57"
decimal = 98.3
type(num)
type(textnum)
type(decimal)
text_num_as_int= int(textnum)
total_sum= num + textnum_as_int + decimal
print(total_sum)
8. calculate the number of minutes in a year using variables for each unit of time. print a
statement that describes what your code does also. Create three variables to store no of
days in a year, minute in a hour, hours in a day, then calculate the total minutes in a year
and print the values
(hint) total number of minutes in an year =No.of days in an year * Hours in a day * Minutes
in an hour
Ans:
days_in_year=365
minutes_in_hour=60
hours_in_day=24
total_minutes_in_year=days_in_year*hours_in_day*minutes_in_hour
print(total_minutes_in_year)
525600
9. Write Python code that asks the user to enter his/her name and then output/prints
his/her name with a greeting.
An example runs of the program:
Please enter you name: Tony
Hi Tony, welcome to Python programming :)
Ans:
user_name = input("Please enter your name: ")
print("Hi " + user_name + ", welcome to Python programming :)")
10. Name your file: PoundsToDollars.py
Write a program that asks the user to enter an amount in pounds (£) and the program
calculates and converts an amount in dollar ($)
An example runs of the program:
Please enter amount in pounds: XXX
£ XXX are $ XXX
Ans:
rupee = float(input("Enter the amount in rupee: "))
dollar= rupee/converstion_rate
print(f"the ampunt in dollar is:{dollar:.2f}")