Question 5 Assume you issued the following command in a python 3 interactive shell: courses = 'ops435,
Question:
Question 5
Assume you issued the following command in a python 3 interactive shell:
courses = 'ops435, ndd430, int420, sec625'
What will be the output for each of the folloiwng Python commands?
- print(courses[0])
- print(len(courses))
- print(type(courses.split(',')))
- print(courses[2:5][0])
Question 6
Read the following script:
#!/usr/bin/env python3
def vowel_counter(target_string):
"Does a thing, counts stuff, doesn't work, fix later :P"
vowel_tally = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
for char in test_string.lower():
if char in vowel_tally.keys():
vowel_tally[char] += 1
return vowel_tally
if __name__ == "__main__":
test_string = "It was the best of times, it was the blurst of times."
results = vowel_counter(test_string)
Answer the following question:
What does this line do: if char in vowel_tally.keys():
Be specific. Explain only this line, don't refer to other lines.
Question 7
Read the following script:
#!/usr/bin/env python3
def vowel_counter(target_string):
"Does a thing, counts stuff, doesn't work, fix later :P"
vowel_tally = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
for char in test_string.lower():
if char in vowel_tally.keys():
vowel_tally[char] += 1
return vowel_tally
if __name__ == "__main__":
test_string = "It was the best of times, it was the blurst of times."
results = vowel_counter(test_string)
Answer the following question:
A new user decides to enter the following lines to the end of the script:
new_results = vowel_counter("Hello World")
print(new_results['e'])
What number do they expect to get?
What number actually gets printed?
Question 8
Read the following script:
#!/usr/bin/env python3
def vowel_counter(target_string):
"Does a thing, counts stuff, doesn't work, fix later :P"
vowel_tally = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
for char in test_string.lower():
if char in vowel_tally.keys():
vowel_tally[char] += 1
return vowel_tally
if __name__ == "__main__":
test_string = "It was the best of times, it was the blurst of times."
results = vowel_counter(test_string)
Answer the following question:
What is the meaning of the line: #!/usr/bin/env python3
Why is it here?
Question 9
Read the following script:
#!/usr/bin/env python3
def vowel_counter(target_string):
"Does a thing, counts stuff, doesn't work, fix later :P"
vowel_tally = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
for char in test_string.lower():
if char in vowel_tally.keys():
vowel_tally[char] += 1
return vowel_tally
if __name__ == "__main__":
test_string = "It was the best of times, it was the blurst of times."
results = vowel_counter(test_string)
Answer the following question:
In a sentence, what does this script do?
Question 10
You are asked by your manager to make a short script by the end of today. Your script should check if a particular website is reachable, and measure the time it takes to load. Will you choose to use Bash or use Python in this case? Justify your answer.
If you aren't sure, what are some questions you would ask your manager about the script requirements?
Principles of Communications Systems, Modulation and Noise
ISBN: 978-8126556793
7th edition
Authors: Rodger E. Ziemer, William H. Tranter