1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dmitry_Shevchenko [17]
3 years ago
11

How to implement switch statement in Python?

Computers and Technology
2 answers:
gregori [183]3 years ago
8 0
Make sure there is a function/method to handle the default case. Next, make a dictionary object and store each of the function beginning with the 0th index. After that, write a switch() function accepting the day of the week as an argument.
Jet001 [13]3 years ago
5 0

Answer:

Switch-case statements are a powerful tool for control in programming. In this article, Sreeram Sceenivasan goes over you can use a switch-case statement in Python.

Explanation:

Python doesn’t need a switch statement. You can do exactly the same thing with if/elif/else statements.

You might be interested in
Write a program that utilizes a loop to read a set of five floating-point values from user input. Ask the user to enter the valu
rjkz [21]

Answer:

Python code is given below

Explanation:

# create an empty array

arr = []

# loop 5 times

for i in range( 0 , 5 ):

   x = float(input('Enter a number : '))

   # add x to arr

   arr.append( x )

sum = 0

# find the sum of all elements in arr

for x in arr:

   sum += x

# calculate average

average = sum / len(arr)

print('\n%15s %15s\n' %('Original Value' , 'Interest Value'))

for Original_value in arr:

   # calculate interesr value

   Interest_Value = Original_value * 0.2

   print('%10f %15f' %( Original_value , Interest_Value ))

print('\nTotal :', sum)

print('Average :', average)

print('Maximum :', max(arr))

print('Miniimum :', min(arr))

3 0
4 years ago
When an author produce an index for his or her book, the first step in this process is to decide which words should go into the
Igoryamba

Answer:

import string

dic = {}

book=open("book.txt","r")

# Iterate over each line in the book

for line in book.readlines():

   tex = line

   tex = tex.lower()

   tex=tex.translate(str.maketrans('', '', string.punctuation))

   new = tex.split()

   for word in new:

       if len(word) > 2:

           if word not in dic.keys():

               dic[word] = 1

           else:

               dic[word] = dic[word] + 1

for word in sorted(dic):

   print(word, dic[word], '\n')

                 

book.close()

Explanation:

The code above was written in python 3.

<em>import string </em>

Firstly, it is important to import all the modules that you will need. The string module was imported to allow us carry out special operations on strings.

<em>dic = {} </em>

<em>book=open("book.txt","r") </em>

<em> </em>

<em># Iterate over each line in the book</em>

<em>for line in book.readlines(): </em>

<em> </em>

<em>    tex = line </em>

<em>    tex = tex.lower() </em>

<em>    tex=tex.translate(str.maketrans('', '', string.punctuation)) </em>

<em>    new = tex.split() </em>

<em />

An empty dictionary is then created, a dictionary is needed to store both the word and the occurrences, with the word being the key and the occurrences being the value in a word : occurrence format.

Next, the file you want to read from is opened and then the code iterates over each line, punctuation and special characters are removed from the line and it is converted into a list of words that can be iterated over.

<em />

<em> </em><em>for word in new: </em>

<em>        if len(word) > 2: </em>

<em>            if word not in dic.keys(): </em>

<em>                dic[word] = 1 </em>

<em>            else: </em>

<em>                dic[word] = dic[word] + 1 </em>

<em />

For every word in the new list, if the length of the word is greater than 2 and the word is not already in the dictionary, add the word to the dictionary and give it a value 1.

If the word is already in the dictionary increase the value by 1.

<em>for word in sorted(dic): </em>

<em>    print(word, dic[word], '\n') </em>

<em>book.close()</em>

The dictionary is arranged alphabetically and with the keys(words) and printed out. Finally, the file is closed.

check attachment to see code in action.

7 0
3 years ago
Devices that integrate the computer case (chassis) and system components into the monitor, but have an external keyboard and mou
stepladder [879]

An all-in-one computer is the device that that integrate the computer case (chassis) and system components into the monitor but have an external keyboard and mouse.

<h3>What is an all-in-one computer?</h3>

All-in-one computer are Personal computer that looks like laptop for one;s specific desk.

The all-in-one computer are self-contained units, have a display and the PC hardware behind it in a sleek and slim package.

In conclusion, the all-in-one computer is the device that that integrate the computer case (chassis) and system components into the monitor but have an external keyboard and mouse.

Read more about computer

<em>brainly.com/question/24540334</em>

6 0
2 years ago
You are going to do a bubble sort on the following list. What are the missing members of the list? Select 3 options.
Nadya [2.5K]
The bubble sort makes multiple passes through a list. It compares adjacent items and exchanges those that are out of order. Each pass through the list places the next largest value in its proper place. In essence, each item “bubbles” up to the location where it belongs.
4 0
3 years ago
Read 2 more answers
Using the Multiple-Alternative IFTHENELSE Control structure write the pseudocode to solve the following problem to prepare a con
ASHA 777 [7]

Answer:

1. Start

2. Input Name, Jobs, Hours, Code

3. If Code == 'J' then

3.1 Pay = 20.00 * Hours

4. Else if Code == 'C' then

4.1 Pay = 15.00 * Hours

5. Else if Code == 'A' then

5.1 Pay = 10.00 * Hours

6. Output Name, Job, Hours, Pay

Explanation

This line starts the Pseudocode

1. Start

This line gets user inputs

2. Input Name, Jobs, Hours, Code

The following if and else statement determine the pay

3. If Code == 'J' then

3.1 Pay = 20.00 * Hours

4. Else if Code == 'C' then

4.1 Pay = 15.00 * Hours

5. Else if Code == 'A' then

5.1 Pay = 10.00 * Hours

This line prints the required output

6. Output Name, Job, Hours, Pay

7 0
3 years ago
Other questions:
  • In order to protect your computer from the newest virus, which of the following should you do after you've installed a virscan s
    9·1 answer
  • The __________ is the continuity of control of evidence that makes it possible to account for all that has happened to evidence
    14·2 answers
  • Python
    6·1 answer
  • On the server side, the database environment must be properly configured to respond to clients' requests in the fastest way poss
    12·1 answer
  • If a large organization wants software that will benefit the entire organization—what's known as enterprise application software
    7·1 answer
  • Fix the two words that are used incorrectly.
    10·2 answers
  • If you need any answer answered faster check out Wolframalpha.com
    14·2 answers
  • How to write my name in binary code ? Rivas
    7·2 answers
  • How do I mark brainlyist
    7·2 answers
  • What is the result of a network technician issuing the command ip dhcp excluded-address 10. 0. 15. 1 10. 0. 15. 15 on a cisco ro
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!