Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please write the follwing code using Python 3. Also, please show all outputs. 1. Using the keys method for dictionaries and the sort method for

Please write the follwing code using Python 3. Also, please show all outputs.

1. Using the keys method for dictionaries and the sort method for lists, write a for loop that prints the keys and corresponding values of a dictionary in the alphabetical order of the keys.

2. As an alternative to the range function, some programmers like to increment a counter inside a while loop and stop the while loop when the counter is no longer less than the length of the array. Rewrite the following code using a while loop instead of a for loop.

a = [7,12,9,14,15,18,12] b = [9,14,8,3,15,17,15] big = [ ] for i in range ( len ( a ) ): big.append ( max ( a [ i ],b [ i ] ) ) 

1. Write a loop that reads each line of a file. It should count the number of characters in each line and keep track of the total number of characters read. Once you have a total of 1,000 or more characters, break from the loop. (You can use a break statement to do this.)

2. Modify the program written in question 3 so that it doesn't count characters on any line that begins with a pound sign (#).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions