Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

Exercise For Variable, Data Type & Data Structure

Q1 Replace "type here" on line below with "Hello World!"


print("type here")

Q2 You can assign "Hello World!" to the variable below on my_text.

my_text=""
print(my_text)

Q3
name=input("Please enter your name.")
#Type your answer here.
str="Hello!, ".format()

print(str)

Q4# Type here. Assign a number to the variable: glass_of_water

glass_of_water=

print("I drank", glass_of_water, "glasses of water today.")

Q5#Assign an integer to the variable, then print it.

men_stepped_on_the_moon=
print()

Q6Using type() function assign the type of the variable to answer_1, then print it.
men_stepped_on_the_moon=12

#Type your code here.

answer_1=

print(answer_1)

Q7 #my_grade variable is a string (because it's in quotes). On line 9, convert it


to an integer.

my_grade="10"

answer_5=

print(answer_5)

Q8#my_temp variable is a float (because it has decimals). On line 9, convert it to


an integer.

my_temp=97.70

answer_6=
print(answer_6)

Q9#GWP denotes the total economic activity created by the world population
collectively in a year.

gross_world_product=84.84

gwp_str=

answer_8="In 2018 gross product of the world (GWP) was " + gwp_str + " in trillion
US dollars."

print(answer_8)

Q10Assign the first element of the list to answer_1 on line 2


lst=[11, 100, 99, 1000, 999]
answer_1=

print(answer_1)

Q11Append method to add items to the end of Python Lists


gift_list=['socks', '4K drone', 'wine', 'jam']
# Type your code here.

print(gift_list)

Q12Lists can hold many type of data inside them. You can even add another list to a
list as its element. This is called nested data in Python.

#On line below, this time add the sub-list: ["socks", "tshirt", "pajamas"] to the
end of the gift_list.

gift_list=['socks', '4K drone', 'wine', 'jam']


# Type your code here.

print(gift_list)

Q13Insert method to add to a specified index of a Python List


On line below , this time insert "slippers" to index 3 of gift_list.

gift_list=['socks', '4K drone', 'wine', 'jam']


# Type your code here.

print(gift_list)

Q14With .index() method you can learn the index number of an item inside your list.
Assign the index no of 8679 to the variable answer_1.

lst=[55, 777, 54, 6, 76, 101, 1, 2, 8679, 123, 99]


# Type your code here.

answer_1=

print(answer_1)

Q15Using .append() method, add a new list to the end of the list which contains
strings: "Navigator" and "Suburban".

lst=["CRV", "Outback", "XC90", "GL", "Cherokee", "Escalade"]


# Type your code here.

print(lst)

Q16Using .reverse() method, reverse the list.

lst=[55, 777, 54, 6, 76, 101, 1, 2, 8679, 123, 99]


# Type your code here.

print(lst)

Q17What is the sum of all the numbers in the list?

lst=[55, 6, 777, 54, 6, 76, 101, 1, 6, 2, 6]

# Type your code on line :


answer_1=

print(answer_1)

Q18 When was Plato born?

dict={"name": "Plato", "country": "Ancient Greece", "born": -427, "teacher":


"Socrates", "student": "Aristotle"}

#Type your answer below.


answer_1=

print(answer_1)

Q19Change Plato's birth year from B.C. 427 to B.C. 428.

dict={"name": "Plato", "country": "Ancient Greece", "born": -427, "teacher":


"Socrates", "student": "Aristotle"}

#Type your answer below.

print(dict["born"])

Q20Dictionaries can have nested data too. Also, you can add a new key to a
dictionary as they are mutable (changeable). Try to add the key "work" to dict with
values shown below.
"work": ["Apology", "Phaedo", "Republic", "Symposium"]

dict={"name": "Plato", "country": "Ancient Greece", "born": -427, "teacher":


"Socrates", "student": "Aristotle"}

#Type your answer below.

print(dict)

Q21Using .get() method print the value of "son's eyes".

dict = {"son's name": "Lucas", "son's eye color": "green", "son's height": 32,
"son's weight": 25}

#Type your answer inside the print.


ans_1=

print (ans_1)

Q22Replace the (.) with (!)

str="It's always darkest before dawn."

#Type your code here.

print(str)

Q23Make the string so that everything is properly and first letter is capital with
one function.

str="there are no traffic JamS Along The extra mile."

#Type your answer here.

print(str)

Q24Does the string start with an A?

Assign a boolean answer to the ans_1 variable.

str="There are no traffic jams along the extra mile."


# Type your code here.

ans_1=

print(ans_1)
Q25Does it end with a fullstop (.) ?

str="There are no traffic jams along the extra mile."


# Type your code here.

ans_1=

print(ans_1)

Q26Using .index() method, identify the index of character: (v).

str="The best revenge is massive success."

# Type your code here.

ans_1=

print(ans_1)

Q27Using .find() method, identify the index of character: (m).

str="The best revenge is massive success."

# Type your code here.

ans_1=

print(ans_1)

Q28What is the length of the given string?

str="1.975.000"

# Type your code here:

ans_1=

print(ans_1)

Q29Using input() function ask for user's name.

#Type your answer here.

ans_1=

print("Hello!, " + ans_1)

Q30This time ask the user a numerical question, such as, "Please enter your age."
See what type of data input() returns.
#Type your code here.
ans_1=

print(type(ans_1))

Q31Create a converter that will ask for amount of days and convert it to years,
then print it.

Using int() function convert the user's answer to integer. And then make your
calculation.

You can ask something like: "How many days would you like to convert to a year?"

# Type your answer here.

message=

result=

print(result)

Q32Create a range from 0 to 50, excluding 50.

#Type your answer here.

rng=

print(rng)
Type something so that Python gives a TypeError.
Q33Create a range from 100 to 160 with steps of 10. Then print it as a list.

Q34Can you you create a list from 1300 to 700 with descending steps of 100? Is your
stop value included in the list?

Q35Type something so that Python gives a NameError.

Q36Type something so that Python gives a SyntaxError.

Q37Type something so that Python gives a TypeError.

Q38Type something so that Python gives a IndexError.

Q39Type something so that Python gives a KeyError.

Q40Type something so that Python gives a AttributeError.

Q41Type something so that Python gives a ValueError.

Q42Three MBA students purchased a different asset yesterday at the below listed
price. Each sold their asset today at the listed selling price.
Calculate the percent return for each student rounded to two decimal points.
Student buy sell
Jen $25.50 $40.20
Jacobi $103.30 $125.00
Mark $86.02 $91.41
Calculate the maximum of the LIST of returns.

Divide 72 by 5 and find both the integer and the remainder.

How would you code the minimum of prime numbers 0-10?

You go to the store with $15 to buy pears, each pear is a $1.35, how many pears can
you buy? (You cannot buy partial pears so round your results).

You might also like