ACTUAL QUESTIONS AND CORRECTLY
WELL DEFINED ANSWERS LATEST
ALREADY GRADED A+
mylist = [5, 3, 7, 9, 1, 2]
mylist.pop()
mylist.insert(2, 4)
mylist.sort()
for i in mylist:
print(i, end = ' ') - ANSWERS-# Q32
mylist = [5, 3, 7, 9, 1, 2]
mylist.pop()
mylist.insert(2, 4)
mylist.sort()
for i in mylist:
print(i, end = ' ')
# output
# 1, 2, 3, 5, 7, 9
,number = input("Enter a number: ") # assume the user
enters 5.0
try: x = int(number)
print("x is the integer", x)
except: x = float(number)
print("x is the float", x) - ANSWERS-# Q33
number = input("Enter a number: ") # assume the user
enters 5.0
try:
x = int(number)
print("x is the integer", x)
except:
x = float(number)
print("x is the float", x)
# output
# ** user enters 5
# x is the integer 5
# ** user enters 5.9
# x is the float 5.9
# if program has decimal will print as float
, List 5 good coding practices that have been mentioned in
this course. - ANSWERS-# Q1
# always comment your code
# keep your code simple
# test your code often, work through it in groups
# be consistent with your code
# use good identifying variables
# write as few of lines as possible
2. In the following dictionary, identify the keys and values.
Write the command to add the items 'Orange' and 1 to the
dictionary. What does the command print(mydict.items())
output to the console? mydict = {'Apple' : 3, 'Pear' : 5,
'Banana' : 2} - ANSWERS-# Q2
mydict = {'Apple' : 3, 'Pear' : 5, 'Banana' : 2}
mydict['Orange'] = 1
print(mydict.items()) # prints items as list
print(mydict) # **** whats diff ??? ****
# cannot do this, a dictionary does not have append or add
# mydict.append("'Orange' : 1")