Sheet No.1+solution

You might also like

You are on page 1of 2

Department: Information Technology

Course Name: Python


Sheet No.1
1. Create a string variable named wel and assign it a value "welcome" then
print out the value of wel with its type in the same line.

2. Create the following:


a) Two string variables, the string variables should be
named string_one and string_two, string_one should contain the
word "Hi", string_two should contain the word "everybody", then
print out the value of "Hi everybody:)"
b) An integer variable, the integer variable should be
named my_int and should contain the number 30, then print out the
value of my_int with its type in the different lines
c) A floating point variable, the floating point variable should be
named my_float and should contain the number 10.35, then print
out the value of my_float

3. Create three variables (a, b, and c) as floating point numbers. Assign a


value of 9.5 to a, assign a value of 5.0 to b, and then make c equal to the
sum of those two variables. Print out the operation that you made with two
those variables and the contents of the c variable.

4. Repeat prob3.0 but print out the content of the variable c as an integer.

5. Create integers x and y and assign them values 98 and 60 simultaneously


on the same line, then print out the value of x and y simultaneously with
one command.

6. Create a variable named why as an integer and do the following:


a) assign it a value 10, then print out the content of the variable.
b) assign it a value 20, then print out the content of the variable.
c) assign it a value 10, then print out the content of the variable.
Each time you print out the content you should print out also the id, explain
the difference and the similarity of the id
Department: Information Technology
Course Name: Python
Solutions Sheet No.1
1. wel="welcome,"
print(wel, type(wel))

2. a) string_one="Hi"
string_two="everybody"
print(string_one+" "+string_two+":)")

b) my_int=30
print(my_int)
print(type(my_int))

c) my_float=10.35
print(my_float)

3. a=9.5
b=5.0
c=a+b
print("a+b=",c)

4. a=9.5
b=5
c=a+b
print("a+b=",int(c))

5. x,y=98,60
print(x,y)

6. why=10
print(why,id(why))
why=20
print(why,id(why))
why=10
print(why,id(why))
because the integer number is immutable

You might also like