In: Computer Science
plz answers these short Qs in python language
Q1-Given three int variables that have been given values, areaCode, exchange, and lastFour, write a string expression whose value is the string equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression's value would be "212-867-5309"
Q2-Write statement that defines plist to be a list of the following ten elements: 10, 20, 30, ..., 100 in that order.
Q3-Associate True with the variable has_dups if the list list1 has any duplicate elements (that is if any element appears more than once), and False otherwise
Q4-Given that plist has been defined to be a list of 30 elements, add 5 to its last element. You can assume that the last element is a number.
.
Python version : 2.7
1.
# str function converts int to string
# + concatenates the string
areaString = str(areaCode)+"-"+str(exchange)+"-"+str(lastFour)
print(areaString)
2.
# creates a list plist containing ten elements 10,20,30,...,100 in that order
plist = [10,20,30,40,50,60,70,80,90,100]
3.
has_dups = False # set has_dups = False
# loop over list list1
for i in range(len(list1)):
# if count of any elements in list1 is greater than 1 then set has_dups to True
if(list1.count(list1[i]) > 1):
has_dups = True
4.
# plist[-1] refers to the last element of plist
# the below statement adds 5 to the last element of plist
plist[-1] = plist[-1] + 5