Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Carry out basic Python exercises that are provided in the shared document below ( Python _ Basics ) . Also, explain your work using comments

Carry out basic Python exercises that are provided in the shared document below (Python_Basics). Also, explain your work using comments in the code cell.
Note: Use a single Jupyter Notebook for all the tasks and clearly document each section using comments and markdowns. Save and submit your output as an HTML file. Word documents or PDFs are not allowed.
Answer the following questions and then explain briefly in words how the code works. (Note:
Do not just provide output but you must explain) You can use the interactive python tutor tool to help you understand code execution
1. Basic syntax. Write the following codes and comment on output for each line.
S=Hello World!
print(S)
print(type(S))
print(S[1])
print(S[2:5])
print(len(S))
print(S.lower())
2. Given the following code, what is printed? Why is z output not printed? How to fix it? Is
there another way of printing z output? What is z data type?
x=10
print(type(x))
y=2.8
print(type(y))
z=5*x+2*y
#z
3. Given the following code, what is printed.
x =7
y = x
x =3
print(x,',', y)
4. How many times is the condition tested ?
i =0
while i <20:
print(i)
i+=1
5. What is printed given the code below? What does def mean and do?
def swap(val1, val2):
tmp = val1
val1= val2
val2= tmp
x =10
y =5
swap(x, y)
print(x,",",y)
6. Complete the missing code for the for loop to produce the output shown. Note: There are
different solutions that can produce the same result.
for i in _____________:
print (i)
2
5
8
11
7. What will be printed by the following code?
x =[1,2,3,4,5,6]
y = x
x[1]=42
print (y)
8. What is the output from the following code?
alist =[6,8,12,13]
alist[3]% alist[1]
9. What is a tuple? Given the tuple, whats the output from the following code?
tup =('physics', 'chemistry', 1997,2000,2001,1999)
print ( tup[2])
print (tup[1:4])
10. Given the tuple above, what is the result of the following code?
tup[2]=1998
print(tup)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

How does micromarketing differ from niche marketing?

Answered: 1 week ago

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago