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

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?

  1. print(courses[0])
  2. print(len(courses))
  3. print(type(courses.split(',')))
  4. 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?



Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!