Python assignment 1
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
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)
Ans:
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:
Ans:
dollar= rupee/converstion_rate