-
Notifications
You must be signed in to change notification settings - Fork 2
MyProgramming Lab
PorryChen edited this page Dec 17, 2017
·
16 revisions
60002
answer:key:
none of the above # (--the textbook. the instructor. the homework programs.--)
60006
answer:key:
Turing
51180
Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and associates that value with total. Thus your code should associate 11 + 22 + 33 +... + 4949 + 50*50 with total. Use no variables other than k and total. Instructor Notes: Note: You must use a while statement.
answer:key:
k = 1
total = 0
while k < 51:
total += k ** 2
k += 1
51181
Given that n refers to a positive int use a while loop to compute the sum of the cubes of the first n counting numbers, and associate this value with total. Use no variables other than n, k, and total.
answer:key:
k = 0
total = 0
while k < n:
total += (k + 1) ** 3
k += 1
51176
Use two variables k and total to write a for loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. Thus, your code should put 11 + 22 + 33 +... + 4949 + 50*50 into total. Use no variables other than k and total.
answer:key:
total = 0
for k in range(0, 50):
total += (k + 1) ** 2
51259
Associate the average of the numbers from 1 to n (where n is a positive integer value) with the variable avg.
answer:key:
avg = 0
for i in range(1, n + 1):
avg += i
if i == n:
avg /= i
51250
Assume there is a variable, h already associated with a positive integer value. Write the code necessary to compute the sum of the first h perfect squares, starting with 1. (A perfect square is an integer like 9, 16, 25, 36 that is equal to the square of another integer (in this case 33, 44, 55, 66 respectively).) Associate the sum you compute with the variable q. For example, if h is 4, you would assign 30 to q because the first 4 perfect squares (starting with 1) are: 1, 4, 9, 16 and 30==1+4+9+16.
answer:key:
q = 0
for i in range(1, h + 1):
q += i ** 2
51286
An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ..., the distance is 2 while in the sequence 6, 12, 18, 24, ..., the distance is 6. Given the positive integer distance and the positive integer n, associate the variable sum with the sum of the elements of the arithmetic progression from 1 to n with distance distance. For example, if distance is 2 and n is 10, then sum would be associated with 25 because 1+3+5+7+9 = 25.
answer:key:
sum = 0
for i in range(1, n + 1, distance):
sum += i
51094
answer:key:
bridge_players += 4
51189
Write a statement that increments total by the value associated with amount. That is, add the value associated with amount to that associated with total and assign the result to total.
answer:key:
total += amount
51097
Write a loop that reads strings from standard input, where the string is either "duck" or "goose". The loop terminates when "goose" is read in. After the loop, your code should print out the number of "duck" strings that were read. Instructor Notes: 1. When you input the string, do not use a prompt message. To input the string use: variable = input() 2. When you print the final result, only print the number of ducks. Do not print any text with the result.
answer:key:
ducks = 0
strings = input()
while strings != "goose":
ducks += 1
strings = input()
print(ducks)
51135
You have a unique ID number, which is represented by the variable id, containing a string of numbers. Write a program that continuously takes strings to standard input. If the string is not your ID number, print "This is not your ID number." If it is, print "This is your ID number: " followed by the number, and terminate the loop.
answer:key:
while input() != id:
print("This is not your ID number.")
else:
print("This is your ID number:", id)
51073
answer:key:
send_signal()
51136
Write a definition of the function printDottedLine, which has no parameters and doesn't return anything. The function prints to standard output a single line consisting of 5 periods (".").
answer:key:
def printDottedLine():
print(".....")
51144
Assume that print_error_description is a function that expects one int parameter and returns no value. Write a statement that invokes the function print_error_description, passing it the value 14.
answer:key:
print_error_description(14)
51075
Write the code to call a function named send_variable and that expects a single int parameter. Suppose a variable called x refers to an int. Pass this variable as an argument to send_variable.
answer:key:
send_variable(x)
51075
Write the code to call a function named send_variable and that expects a single int parameter. Suppose a variable called x refers to an int. Pass this variable as an argument to send_variable.
answer:key:
send_variable(x)
51076
Write the code to call a function named send_two and that expects two parameters: a float and an int. Invoke this function with 15.955 and 133 as arguments.
answer:key:
send_two(15.955, 133)
51145
Given print_larger, a function that expects two parameters and returns no value and given two variables, sales1 and sales2, that have already been defined, write a statement that calls print_larger, passing it sales1 and sales2.
answer:key:
print_larger(sales1, sales2)
51137
Write the definition of a function printGrade, which takes one parameter containing a string value and returns nothing. The function prints "Grade: " followed by the string parameter.
answer:key:
def printGrade(grade):
print("Grade:", grade)
51146
Given that add, a function that expects two int parameters and returns their sum, and given that two variables, euro_sales and asia_sales, have already been defined: Write a statement that calls add to compute the sum of euro_sales and asia_sales and that associates this value with a variable named eurasia_sales.
answer:key:
eurasia_sales = add(euro_sales, asia_sales)
51147
Assume that to_the_power_of is a function that expects two int parameters and returns the value of the first parameter raised to the power of the second parameter. Write a statement that calls to_the_power_of to compute the value of cube_side raised to the power of 3 and that associates this value with cube_volume.
answer:key:
cube_volume = to_the_power_of(cube_side, 3)
51155
Write the definition of a function twice, that receives an int parameter and returns an int that is twice the value of the parameter.
answer:key:
def twice(value):
return value * 2
51139
Write the definition of a function square which recieves a parameter containing an integer value and returns the square of the value of the parameter.
answer:key:
def square(side):
return side ** 2
51156
answer:key:
def add(num1, num2):
return num1 + num2
51105
Write a function min that has three str parameters and returns the smallest. (Smallest in the sense of coming first alphabetically, not in the sense of "shortest".)
answer:key:
def min(str1, str2, str3):
if str1 < str2 and str1 < str3:
return str1
elif str2 < str1 and str2 < str3:
return str2
else:
return str3
51140
Write the definition of a function add which recieves two parameters containing integer values and returns their sum.
answer:key:
def add(int1, int2):
return int1 + int2
51151
Write the definition of a function oneLess which recieves a parameter containing an integer value and returns an integer whose value is one less than the value of the parameter.
answer:key:
def oneLess(value):
return value - 1
51157
Define a function called isPositive that takes a parameter containing an integer value and returns True if the paramter is positive or False if the parameter is negative or 0.
answer:key:
def isPositive(value):
return value > 0
51159
Define a function called isSenior that takes a parameter containing an integer value and returns True if the parameter is greater than or equal to 65, and False otherwise.
answer:key:
def isSenior(value):
return value >= 65
51164
Define a function called isEven that takes a parameter containing an integer value and returns True if the parameter is even, and False otherwise.
answer:key:
def isEven(value):
return value % 2 == 0
51174
Define a function called min that takes two parameters containing integer values and returns the smaller integer of the two. If they have equal value, return either one.
answer:key:
def min(value1, value2):
return value1 if value1 < value2 else value2
51148
max is a function that expects two int parameters and returns the value of the larger one. Two variables, population1 and population2, have already been defined and associated with int values. Write an expression (not a statement!) whose value is the larger of population1 and population2 by calling max.
answer:key:
max(population1, population2)
51185
Write a statement to open the file yearsummary.txt in a way that erases any existing data in the file.
answer:key:
open('yearsummary.txt', 'w')
51191
Given a file named execution.log write the necessary code to add the line "Program Execution Successful" to the end of the file (add the statement on a new line).
answer:key:
f = open('execution.log','a')
f.write("\nProgram Execution Successful")
51220
Given a file object named output, associate it with a file named yearsummary.txt by opening the file for appending
answer:key:
output = open('yearsummary.txt', 'a')
51221
Given that corpdata is a file object used for reading data and that there is no more data to be read, write the necessary code to complete your use of this object.
answer:key:
corpdata.close()
51222
Use the file object output to write the string "3.14159" to a file called pi. Instructor Notes: Important: The filename has no extension. Also, include code to open the file before you write the string into the file. Do not add a newline character to the end of the string.
answer:key:
output = open('pi', 'w')
output.write('3.14159')
51223
Using the file object input, write code that read an integer from a file called rawdata into a variable datum (make sure you assign an integer value to datum). Open the file at the beginning of your code, and close it at the end. Instructor Notes: Important: the filename has no extension.
answer:key:
f = open('rawdata', 'r')
datum = int(f.read())
f.close()
51356
A file named numbers.txt contains an unknown number of lines, each consisting of a single integer. Write some code that computes the sum of all these integers, and stores this sum in a variable name sum. Instructor Notes: Be sure to include code to open and close the file.
answer:key:
sum = 0
f = open('numbers.txt', 'r')
for line in f:
sum += int(line)
51358
A file named data1.txt contains an unknown number of lines, each consisting of a single integer. Write some code that creates a file named data2.txt and copies all the lines of data1.txt to data2.txt. Instructor Notes: Be sure to include code to open and close both files.
answer:key:
f1 = open('data1.txt', 'r')
f2 = open('data2.txt', 'w')
for line in f1:
f2.write(line)
51362
Two variables, x and y, supposedly hold strings of digits. Write code that converts these to integers and assigns a variable z the sum of these two integers. Make sure that if either x and y has bad data (that is, not a string of digits), z will be assigned the value of -1. Instructor Notes: Use a try/except statement.
answer:key:
z = 0
try:
z += int(x) + int(y)
except ValueError:
z = -1
51363
Two variables, num_boys and num_girls, hold the number of boys and girls that have registered for an elementary school. The variable budget holds the number of dollars that have been allocated to the school for the school year. Write code that prints out the per-student budget (dollar spent per student). If a division by zero error takes place, just print out the word "unavailable". Instructor Notes: Use a try/except statement.
answer:key:
try:
print(budget / (num_boys + num_girls))
except ZeroDivisionError:
print('unavailable')
51162
Write the definition of a function named sum_list that has one parameter, a list whose elements are of type int. The function returns the sum of the elements of the list as an int.
answer:key:
def sum_list(list):
sum = 0
for value in list:
sum += value
return sum
- initialization/creation
51601
Write a statement that defines plist as the list containing exactly these elements (in order): "spam", "eggs", "vikings" .
answer:key:
plist = ['spam', 'eggs', 'vikings']
51194
Write a statement that defines the variable denominations, and associates it with a list consisting of the following six elements: 1, 5, 10, 25, 50, 100, in that order.
answer:key:
denominations = [1, 5, 10, 25, 50, 100]
- indexing
51203
answer:key:
plist = []
51201
Assume that a list of integers named salary_steps that contains exactly five elements has been defined. Write a statement that changes the value of the last element in the list to 160000.
answer:key:
salary_steps[4] = 160000
51195
Given a variable plist, that refers to a non-empty list, write an expression that refers to the first element of the list.
answer:key:
plist[0]
51200
Assume that salary_steps refers to a non-empty list, write a statement that assigns the value 30000 to the first element of this list.
answer:key:
salary_steps[0] = 30000
51205
Given that plist refers to a non-empty list ,write a statement that assigns the int -1 to the last element of the list
answer:key:
plist[len(plist) - 1] = -1
- length and concatenation
51611
Given that plist1 and plist2 both refer to lists, write an expression that evaluates to a list that is the concatenation of plist1 and plist2. Do not modify plist1 or plist2.
answer:key:
plist1 + plist2
51602
answer:key:
len(play_list)
51613
Given that play_list has been defined to be a list, write an expression that evaluates to a new list containing the elements at index 0 through index 4 play_list. Do not modify play_list.
answer:key:
play_list[0:5]
51615
Given that k and j each refer to a non-negative int and that play_list has been defined to be a list with at least j elements, write an expression that evaluates to a new list containing all the elements from the one at index k through the one at index j-1 of list play_list . Do not modify play_list .
answer:key:
play_list[k: j]
51618
Given that worst_offenders has been defined as a list with at least 6 elements, write a statement that defines lesser_offenders to be a new list that contains all the elements from index 5 of worst_offenders and beyond. Do not modify worst_offenders.
answer:key:
lesser_offenders = worst_offenders[5:]
51620
Given that plist has been defined to be a list, write an expression that evaluates to True if 3 is an element of plist.
answer:key:
3 in plist
51213
Given: a variable current_members that refers to a list, and a variable member_id that has been defined. Write some code that assigns True to a variable is_a_member if the value associated with member_id can be found in the list associated with current_members, but that otherwise assigns False to is_a_member. Use only current_members, member_id, and is_a_member.
answer:key:
if member_id in current_members:
is_a_member = True
else:
is_a_member = False
51212
answer:key:
a.reverse()
51610
answer:key:
play_list.sort()
51603
Given a variable named plist that refers to a list, write a statement that adds another element, 5 to the end of the list.
answer:key:
plist.append(5)
51609
Given that k refers to a non-negative int and that alist has been defined to be a list with at least k+1 elements, write a statement that removes the element at index k.
answer:key:
alist.remove(alist[k])
51607
Given that alist has been defined to be a non-empty list (that is with at least one element), write a statement that removes its first element.
answer:key:
alist.remove(alist[0])
51275
Given the lists list1 and list2 that are of the same length, create a new list consisting of the first element of list1 followed by the first element of list2, followed by the second element of list1, followed by the second element of list2, and so on (in other words the new list should consist of alternating elements of list1 and list2). For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6], then the new list should contain [1, 4, 2, 5, 3, 6]. Associate the new list with the variable list3.
answer:key:
index = 0
list3 = []
while index < len(list1):
list3.append(list1[index])
list3.append(list2[index])
index += 1
51288
In the following sequence, each number (except the first two) is the sum of the previous two number: 0, 1, 1, 2, 3, 5, 8, 13, .... This sequence is known as the Fibonacci sequence. Given the positive integer n create a list consisting of the portion of the Fibonacci sequence less than or equal to n. For example, if n is 6, then the list would be [0, 1, 1, 2, 3, 5] and if n is 1, then the list would be [0, 1, 1]. Associate the list with the variable fib.
answer:key:
fib = [0, 1]
index = 1
while fib[index] + fib[index - 1] <= n:
fib.append(fib[index] + fib[index - 1])
index += 1
51295
Given the lists, lst1 and lst2, create a new sorted list consisting of all the elements of lst1 that also appears in lst2. For example, if lst1 is [4, 3, 2, 6, 2] and lst2 is [1, 2, 4], then the new list would be [2, 2, 4]. Note that duplicate elements in lst1 that appear in lst2 are also duplicated in the new list. Associate the new list with the variable new_list, and don't forget to sort the new list.
answer:key:
new_list = []
for val1 in lst1:
for val2 in lst2:
if val1 == val2:
new_list.append(val1)
51210
Given a variable temps that refers to a list, all of whose elements refer to values of type float, representing temperature data, compute the average temperature and assign it to a variable named avg_temp. Besides temps and avg_temp, you may use two other variables -- k and total.
answer:key:
k = 0
total = 0
while k < len(temps):
total += temps[k]
k += 1
avg_temp = total / len(temps)
51219
A list named parking_tickets has been defined to be the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the list contains the number of tickets given on January 1; the last element contains the number of tickets given today.) Write some code that associates most_tickets with the largest value found in parking_tickets. You may, if you wish, use one additional variable, k.
answer:key:
most_tickets = 0
for k in parking_tickets:
if most_tickets < k:
most_tickets = k
51263
answer:key:
sum = 0
for value in numbers:
if value > 0:
sum += value
51150
Assume that print_list is a function that expects one parameter, a list. The function prints the contents of the list; it does not return a value. Assume that inventory is a list, each of whose elements is an int. Write a statement that prints the contents of the list inventory by calling the function print_list.
answer:key:
print_list(inventory)
51701
answer:key:
t = (42, 56, 7)
51702
Given that t has already been defined and refers to a tuple, write an expression whose value is the tuple's length.
answer:key:
len(t)
51703
answer:key:
t[0]
51704
answer:key:
k = t[0]
51707
Given that play_list has been defined and refers to a list, write a statement that associates t with a tuple containing the same elements as play_list.
answer:key:
t = tuple(play_list)
51007
Given a variable t that is associated with a tuple whose elements are numbers, write some statements that use a while loop to count the number of times the first element of the tuple appears in the rest of the tuple, and associate that number with the variable repeats. Thus if the tuple contains (1,6,5,7,1,3,4,1), then repeats would be assigned the value 2 because after the first "1" there are two more "1"s.
answer:key:
repeats = 0
if len(t) > 0:
first = t[0]
index = 1
while index < len(t):
if t[index] == first:
repeats += 1
index += 1
51262
Given the list my_list containing integers, create a list consisting of all the even elements of my_list. Associate the new list with the variable new_list.
answer:key:
new_list = []
for value in my_list:
if value % 2 == 0:
new_list.append(value)
51760
answer:key:
s[3]
51761
answer:key:
s[len(s) - 1]
51762
###### Write an expression whose value is the str that consists of the second to last character of the str associated with s.answer:key:
s[len(s) - 2]
51763
Write an expression whose value is the str that consists of the third to last character of the str associated with s.
answer:key:
s[-3]
51754
answer:key:
'Hello' + 'World'
51838
Given a String variable address, write a String expression consisting of the string "http://" concatenated with the variable's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com".
answer:key:
"http://" + address
51839
Write an expression that concatenates the String variable suffix onto the end of the String variable prefix .
answer:key:
prefix + suffix
51755
Write an expression that is the concatenation of the str associated with s1 and that associated with the str s2.
answer:key:
s1 + s2
51869
Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"
answer:key:
'(' + word + ')'
51756
Write an expression whose value is the concatenation of the three str values associated with name1, name2, and name3, separated by commas. So if name1, name2, and name3, were (respectively) "Neville", "Dean", and "Seamus", your expression's value would be "Neville,Dean,Seamus".
answer:key:
name1 + ',' + name2 + ',' + name3
51764
Write an expression whose value is the str that consists of the first four characters of the str associated with s.
answer:key:
s[:4]
51765
Write an expression whose value is the str that consists of the second through fifth characters of the str associated with s.
answer:key:
s[1:5]
51771
Write an expression whose value is the str consisting of all the characters (starting with the sixth) of the str associated with s.
answer:key:
s[5:]
51851
Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String containing the first character of the value of name. So if the value of name were "Smith" the expression's value would be "S".
answer:key:
name[0]
51772
Given that s refers to a string, write an expression that evaluates to a string that is a substring of s and that consists of all the characters of s from its start through its ninth character.
answer:key:
s[:9]
51757
answer:key:
s[0] == 'p'
51767
Write an expression whose value is True if all the letters in the str associated with s are upper case.
answer:key:
s.isupper()
51758
answer:key:
s[:4] != 'ecto'
51759
answer:key:
s[-3:] == 'ism'
51766
Write an expression whose value is True if all the letters in the str associated with s are all lower case.
answer:key:
s.islower()
51769
Given a variable s associated with a str, write an expression whose value is a str that is identical except that all the letters in it are upper-case. Thus, if the str associated with s were "McGraw15", the value of the expression would be "MCGRAW15".
answer:key:
s.upper()
51770
Write an expression whose value is the same as the str associated with s but with all lower caseletters. Thus, if the str associated with s were "McGraw15", the value of the expression would be "mcgraw15".
answer:key:
s.lower()
51773
Given variables first and last, each of which is associated with a str, representing a first and a last name, respectively. Write an expression whose value is a str that is a full name of the form "Last, First". So, if first were associated with "alan" and last with "turing", then your expression would be "Turing,Alan". (Note the capitalization! Note: no spaces!) And if first and last were "Florean" and "fortescue" respectively, then your expression's value would be "Fortescue,Florean".
answer:key:
last[0].upper() + last[1:].lower() + ',' + first[0].upper() + first[1:].lower()
51271
Given the strings s1 and s2 that are of the same length, create a new string consisting of the first character of s1 followed by the first character of s2, followed by the second character of s1, followed by the second character of s2, and so on (in other words the new string should consist of alternating characters of s1 and s2). For example, if s1 contained "hello" and s2 contained "world", then the new string should contain "hweolrllod". Associate the new string with the variable s3.
answer:key:
s3 = ''
index = 0
while index < len(s1):
s3 += s1[index] + s2[index]
index += 1
51272
Given the strings s1 and s2 that are of the same length, create a new string consisting of the last character of s1 followed by the last character of s2, followed by the second to last character of s1, followed by the second to last character of s2, and so on (in other words the new string should consist of alternating characters of the reverse of s1 and s2). For example, if s1 contained hello" and s2 contained "world", then the new string should contain "odlllreohw". Assign the new string to the variable s3.
answer:key:
s3 = ''
index = len(s1) - 1
while index >= 0:
s3 += s1[index] + s2[index]
index -= 1
51273
Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1 and s2 (that is, the first character of s1 followed by the first character of s2, followed by the second character of s1, followed by the second character of s2, and so on. Once the end of either string is reached, no additional characters are added. For example, if s1 contained "abc" and s2 contained "uvwxyz", then the new string should contain "aubvcw". Assign the new string to the variable s3.
answer:key:
s3 = ''
len1 = len(s1)
len2 = len(s2)
length = len1 if len1 < len2 else len2
index = 0
while index < length:
s3 += s1[index] + s2[index]
index += 1
51274
Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1 and s2 (that is, the first character of s1 followed by the first character of s2, followed by the second character of s1, followed by the second character of s2, and so on. Once the end of either string is reached, the remainder of the longer string is added to the end of the new string. For example, if s1 contained "abc" and s2 contained "uvwxyz", then the new string should contain "aubvcwxyz". Associate the new string with the variable s3.
answer:key:
s3 = ''
len1 = len(s1)
len2 = len(s2)
length = len1 if len1 < len2 else len2
index = 0
while index < length:
s3 += s1[index] + s2[index]
index += 1
s3 += s1[length: ] if len1 > len2 else s2[length: ]
51279
Assign True to the variable has_dups if the string s1 has any duplicate character (that is if any character appears more than once) and False otherwise
answer:key:
has_dups = False
s2 = ''
for value in s1:
if value not in s2:
s2 += value
else:
has_dups = True
break
51006
Given a variable t that is associated with a tuple whose elements are strings, write some statements that use a while loop to count the number of tuple elements that are 4-character strings and associate that number with the variable four_letter_word_count.
answer:key:
four_letter_word_count = 0
index = 0
while index < len(t):
if len(t[index]) == 4:
four_letter_word_count += 1
index += 1
51002
Given a variable s that is associated with the empty string, write some statements that use a while loop to associate s with a string consisting of exactly 777 asterisks*
answer:key:
count = 0
while count < 777:
s += '*'
count += 1
51003
Given a variable n that is associated with a positive integer and a variable s that is associated with the empty string, write some statements that use a while loop to associate s with a string consisting of exactly n asterisks* . (So if n were associated with 6 then s would, in the end, be associated with "******" .
answer:key:
index = 0
while index < n:
s += '*'
index += 1
51004
Given a variable n that is associated with a positive integer and a variable s that is associated with the empty string, write some statements that use a while loop to associate s with a string consisting of exactly 2n asterisks * . (So if n were associated with 4 then s would, in the end, be associated with "********" .
answer:key:
index = 0
while index < n:
s += '*' * 2
index += 1
51005
Given a variable s that is associated with non-empty string, write some statements that use a while loop to associate a variable vowel_count with the number of lower-case vowels ("a","e","i","o","u") in the string .
answer:key:
vowel_count = 0
index = 0
while index < len(s):
if s[index] in ("a","e","i","o","u"):
vowel_count += 1
index += 1
51750
Write an expression whose value is the result of converting the int value 42 to a str (consisting of the digit 4 followed by the digit 2).
answer:key:
str(42)
51751
Write an expression whose value is the result of converting the int value associated with x to a str. So if 582 was the int associated with x you would be converting it to the str "582".
answer:key:
str(x)
51752
Write an expression whose value is the result of converting the str value associated with s to an int value. So if s were associated with "41" then the resulting int would be 41.
answer:key:
int(s)
51753
Write an expression whose value is the arithmetic sum of the int associated with x, and the all-digit str associated with s. (Hint: you will need to convert the str to an int.)
answer:key:
x + int(s)
51026
Write a statement to set the value of the variable popStr to a string representation of the value referenced by the variable pop.
answer:key:
popStr = str(pop)
51024
Assume the variable date has been set to a string value of the form mm/dd/yyyy, for example 09/08/2010. (Actual numbers would appear in the string.) Write a statement to assign to a variable named dayStr the characters in date that contain the day. Then set a variable day to the integer value corresponding to the two digits in dayStr.
answer:key:
dayStr = date[3: 5]
day = int(dayStr)