Python programming using def function

Give the user a math quiz where they have
to subtract 2-digit integers. Present them
like this: 67 - 55.
Each time, tell the user whether they are
correct or incorrect. Continue presenting
problems to them until they enter a zero to
quit. At the end print the number right,
the number wrong, and the percent right.

Python Programming Using Def Function Give The User A Math Quiz Where They Haveto Subtract 2-digit Integers.

Answers

Answer 1

Explanation:

For this program we'll need to know a couple concepts which are: while loops, user input, variables, converting strings to integers, and basic arithmetic operators, if statements, and the random module.

So let's first just declare the basic function, we can call this "main", or something a bit more descriptive, but for now I'll name it "main".

def main():

   # code will go here

main()

so now from here, we want to initialize some variables. We need to somehow keep track of how many they get correct and how many they've answered.

These two numbers may be the same, but at times they will be different from each other, so we'll need two variables. Let's just call the variable tracking how much have been answered as "answered" and the variable tracking how much are correct as "correct".

These two will initially be zero, since the user hasn't answered any questions or gotten any correct. So now we have the following code

def main():

   correct = 0

   answered  = 0

main()

Now let's use a while loop, which we break out of, once the user inputs zero. This may be a bit tricky if we use a condition since we'll have to ask for input before, so let's just use a while True loop, and then use an if statement to break out of it at the end of the loop.

Now we want to generate two numbers so we can use the random module. To access the functions from the random module you use the import statement which will look like this "import random". Now that you have access to these functions, we can use the randint function which generates random numbers between the two parameters you give it (including those end points). It says two digits, so let's use the endpoints 10 and 98, and I'll explain later why I'm limiting it to 98 and not 99.

The reason we want to limit it to 98 and not 99, is because it's possible for the two randomly generated numbers to be equal to each other, so the answer would be zero. This is a problem because the zero is used to quit the program. So what we can do in this case, is add one to one of the numbers, so they're no longer equal, but if they're equal to 99, then now we have a three digit number.

Now onto the user input for simplicitly, let's assume they enter valid input, all we have to do is store that input in a variable and convert it into an integer. We can immediately convert the input into an integer by surrounding the input by the int to convert it.

we of course want to display them the equation, and we can either do this through string concatenation or f-strings, but f-strings are a bit more easier to read.

So let's code this up:

import random

def main():

   correct = 0

   answered  = 0

   while True:

       num1 = random.randint(10, 98)

       num2 = random.randint(10, 98)

       

       if num1 == num2:
           num2 += 1

       userInput = int(input(f"{num1} - {num2}"))

main()

from here we first need to check if they entered zero and if so, break out of the loop. If they didn't enter zero, check if the userInput is equal to the actual answer and if it is, then add one to correct and finally add one to answered regardless of whether their answer is correct or not.

Outside the loop to display how much they got correct we can use an f-string just like we did previously. Since sometimes we'll get a non-terminating decimal, we can use the round function so it rounds to the nearest hundreth.

So let's code this up:

import random

def main():

   correct = 0

   answered  = 0

   while True:

       num1 = random.randint(10, 98)

       num2 = random.randint(10, 98)

       if num1 == num2: # the answer would be zero
           num2 += 1 # makes sure the answer isn't zero

       userInput = int(input(f"{num1} - {num2}"))

       if userInput == 0: # first check if they want to stop

           break

       if userInput == (num1 - num2):
           correct += 1

       answered += 1

   print(f"Correct: {correct}\nIncorrect: {answered - correct}\nPercent: {round(correct/answered, 2)}")

main()

and that should pretty much be it. The last line is just some formatting so it looks a bit better when displaying.


Related Questions

Ask the user to think of a number between zero and one hundred. Your goal is to guess the number in as few guesses as possible. The user will inform you if you guessed too high, low or correct. Start by always guessing the middle number 50. If the user informs you it’s too low, then try 75. If 50 was too high, then try 25. Always guess the middle of the range of numbers left. In doing so, the range of numbers will be cut in half after each guess. If done correctly, no more than 7 guesses are needed. Print out “you cheated” if you reach 7 guesses and are still wrong.

Answers

A program in Python that asks the user to think of a number between zero and one hundred and tries to guess the number in as few guesses as possible is given below:

The Program

import random

import math

# Taking Inputs

lower = int(input("Enter Lower bound:- "))

# Taking Inputs

upper = int(input("Enter Upper bound:- "))

# generating random number between

# the lower and upper

x = random.randint(lower, upper)

print("\n\tYou've only ",

round(math.log(upper - lower + 1, 2)),

" chances to guess the integer!\n")

# Initializing the number of guesses.

count = 0

# for calculation of minimum number of

# guesses depends upon range

while count < math.log(upper - lower + 1, 2):

count += 1

# taking guessing number as input

guess = int(input("Guess a number:- "))

# Condition testing

if x == guess:

 print("Congratulations you did it in ",

  count, " try")

 # Once guessed, loop will break

 break

elif x > guess:

 print("You guessed too small!")

elif x < guess:

 print("You Guessed too high!")

# If Guessing is more than required guesses,

# shows this output.

if count >= math.log(upper - lower + 1, 2):

print("\nThe number is %d" % x)

print("\tBetter Luck Next time!")

Read more about python programming here:

https://brainly.com/question/26497128

#SPJ1

What is a privacy data breach

Answers

Answer: A privacy data breach occurs when personal information is stolen or lost or is collected, used or disclosed without authority. A privacy breach occurs when personal information is stolen or lost or is collected, used or disclosed without authority.

Explanation:

Examples of a  data breach might include:

Loss or theft of hard copy notes, USB drives, computers or mobile devices. an unauthorized person gaining access to your laptop, email account or computer network. sending an email with personal data to the wrong person.

What is output by the following code? Select all that apply.

c = 2




while (c < 12):

print (c)
c = c + 3

Answers

When the above code is run via a compiler, the output will be 5.

What is code in programming?

In computer programming, computer code is a set of instructions or a set of rules expressed in a specific programming language (i.e., the source code). It is also the name given to source code after it has been compiled and is ready to execute on a computer.

The print() method outputs the message supplied to the screen or another standard output device. The message can be a string or any other object, which will be transformed to a string before being displayed on the screen.

When the above code is correctly entered into the compiler and rightly indented, the output given is 5.

Learn more about compilers:
https://brainly.com/question/27882492

#SPJ1

What are the architectural features of the data storage system in each proposal

Answers

Answer:

Network storage architecture refers to the physical and conceptual organization of a network that enables data transfer between storage devices and servers. It provides the backend for most enterprise-level operations and allows users to get what they need

Explanation:

Downloading what appears to be a legitimate app, a user installs malware which contains keylogging software. What type of breach is the downloading of malware?
CIA Traid -
explain

Answers

Downloading what appears to be a legitimate app, a user installs malware which contains keylogging software. The type of breach that this downloading of malware is  called option B: integrity.

What is CIA Traid about?

The CIA triad, also known as confidentiality, integrity, and availability, is a concept created to direct information security policies inside a company. To avoid confusion with the Central Intelligence Agency, the approach is sometimes frequently referred to as the AIC triad (availability, integrity, and confidentiality).

Note that In the event of a cyber breach, the CIA triad offers organizations a clear and thorough checklist to assess their incident response strategy. The CIA trio is particularly crucial for identifying vulnerability sources and aiding in the investigation of what went wrong once a network has been infiltrated.

Learn more about malware from

https://brainly.com/question/399317
#SPJ1

See full question below

Downloading what appears to be a legitimate app, a user installs malware which contains keylogging software. What type of breach is the downloading of malware?

answer choices

Confidentiality

Integrity

SMCS School has hired you to set up an Internet connection within the school premises. The Internet connection will be utilized by both the junior and senior sections of the school situated in two different buildings on the same campus. Which of the following types of networks will you install in this scenario?

Answers

The network that will be install in the school premises and will be utilized by both the junior and senior sections of the school situated in two different buildings on the same campus is CAN (Campus Area Network).

Different Type of Networks:

Option 1 : MAN

Metropolitan Area Network is used to set up an Internet connection within the city.

So, this is the wrong option.

Option 2: WAN

Wide Area Network is used to setup an internet connection over a state, province or country.

So, this is the wrong option.

Option 3: CAN

Campus area network is used to setup internet connection within a limited geographical area like school campus, university campus etc. Given scenario is, the Internet connection will be utilized by both the junior and senior sections of the school situated in two different buildings on the same campus. When internet connection is to be used within the campus i.e., between two or three buildings then campus Area Network must be used there.

So, this is the Correct answer.

Option 4: LAN

Local Area Network is used to setup internet connection over the smallest area such as one school building, college buliding but not within the overall campus.

So, this is the wrong option.

To know more about network, visit: https://brainly.com/question/1167985

#SPJ1


Cloud computing is an example of a social networking site

Answers

Answer: no

Explanation:

cloud computing is the delivery of computing services—including servers, storage, databases, networking, software, analytics, and intelligence—over the Internet

No, cloud computing is not an example of a social networking site. Cloud computing refers to the delivery of computing services, including storage, databases, software, and networking, over the internet.

It involves the use of remote servers hosted on the internet to store, manage, and process data, rather than relying on local servers or personal devices.

On the other hand, social networking sites are web platforms that enable users to create profiles, connect with others, and share content, ideas, and interests.

While both cloud computing and social networking sites are technology-related concepts, they serve different purposes.

Cloud computing focuses on the delivery of computing services, while social networking sites focus on facilitating social interactions and content sharing among users.

Thus, the given statement is false.

For more details regarding cloud computing, visit:

https://brainly.com/question/30122755

#SPJ6

The sequence [tex]x_{n}[/tex] is defined, for n > 2, by the recursive formula

[tex]x_{n}[/tex] = [tex]2x_{n - 1}[/tex] + [tex]x_{n - 2}[/tex] where [tex]x_{1}[/tex] = 2 and [tex]x_{2}[/tex] = 3.

Write a program that first invites the user to input a natural number n. Then compute the n-th number in the sequence [tex]x_{n}[/tex] and display it appropriately to the user.

(The solution has to be in the Python programming language!)

Answers

Using the knowledge of the computational language in python it is possible to write a code that write a program that first invites the user to input a natural number n.

Writting the code:

def func(n):

   

   # Base cases:

   # When n reaches 1 then return 2 as X1 = 2.

   if(n == 1):

       return 2

   

   # When n reaches 2 then return 3 as X2 = 3.

   if(n == 2):

       return 3

     

   ans = 2 * func(n-1) + func(n-2)

      return ans

n = int(input("Enter a natural number: "))

print("The" ,n,"-th number of the sequence is: " ,func(n))

See more about python at brainly.com/question/18502436

#SPJ1

how do you think the internet and social media will impact global communities in the next five years?

Answers

I do think that the internet and social media will impact global communities in the next five years as it will bring about huge growth in the nations economy and also more improvement in the healthcare system.

What is social media, and how does it affect the neighborhood?

In actuality, social media can be advantageous for society. People may connect and their relationships may become deeper as a result. Student learning and development are also encouraged by social media. Additionally, it can help firms grow their clientele and increase their revenue.

Therefore, Future communication will be based on the framework established by what is currently referred to as social media, but it will look very different. By 2033, the amount of data that will be accessible to everyone as well as its ability to influence decisions will have undergone the most significant change.

Learn more about social media  from

https://brainly.com/question/3653791

#SPJ1

What is output by the following code? Select all that apply.

c = 0
while (c < 11):
c = c + 6
print (c)

Answers

When the above code is entered into the Python online compilers and run, the output is 12.

What is an online compiler?

An online compiler is a technology that allows you to build and run source code in a variety of computer languages online. For program execution, an online compiler is required. It translates the text-based source code into an executable form known as object code.

The print() function sends the specified message to the screen or another output device. The message can be a string or another object that is converted to a string before being shown on the screen.

Hence, where:

c = 0

while (c < 11):

 c = c + 6

print (c)

Output = 12

Learn more about compilers:
https://brainly.com/question/27882492
#SPJ1

A research scholar has to work as a judge and derive the truth and not as a pleader who is only eager
to prove his case in favour of his plaintiff. Discuss the statement pointing out the objectives of
research.

Answers

A research scholar is a person who focuses primarily and is practical to affect changes in the world, not a judge in which he proves something.

Who is a researcher?

Someone who conducts research is a researcher. This signifies that the person conducts one type of research on a certain topic, which also suggests that only some previously acquired knowledge may be further examined.

The responsibilities of a scholar include: assisting freshmen in learning various cutting-edge approaches to keep graduates current with the area. it is to take control of the group's research, production, and statistical activities. to examine their research and make sure it is original and free of plagiarism.

Learn more about researcher, here:

https://brainly.com/question/14693819

#SPJ1

Below you can see stringSize, which is implemented in Java

Answers

It will return correct values as it will iterate until the length is met (and therefore i is not less than s.length() but is equal to s.length). It is poorly designed as s.length() can be used directly to obtain the number of characters in a string. This function likely has a Big O notation greater than O(n) because - due to the unnecessary loop - it has to iterate again. It also increments size multiple times instead of mutating it once when the for loop is finished to reduce on read/write time

Write and test the “digit” function: Function Prototype: int digit(int n,int k) This function returns the kth digit of the positive integer n. For example, if n is the integer 85,419, then the call digit(n,0) would return the digit 8, and the call digit(n,2) would return the digit 4. Examples: 1. Input: n = 25419 , k = 1 output: 5 2. Input: n = 2 , k = 0 output: 2 3. Input: n = 2 , k = 1 output: index out of bound (return -1) Note: • The digits are numbered from left to right beginning with the “zeroth” digit. • Take input and display output in main function. • Do not use array or string etc.

Answers

Explanation:

You have to just take a number n and after that you just reverse the number after that when the number is reversed you simply apply mod of 10 at  that reversed number and then divide it by 10.

Note:

you have to use while loops when finding reversed number and the place of number to be found

Answer:

fastian broh its call plagrism

Explanation:

You wrote a pseudocode outline of your program using comments. Which character do you use to indicate a line is a comment? O # O/ O& O"​

Answers

It depends on the coding language but assuming you’re studying Python the correct way to comment is with # symbol

17 Can you determine Lack of Encryption and Security Misconfiguration in an organisation?

Answers

It is possible for the person to determine the lack of Encryption and Security Misconfiguration in an organization.

What do you mean by Security misconfiguration?

Security misconfiguration may be defined as a type of security control that is significantly configured or left insecure inaccurately by putting your systems and data at risk. It may arise when essential security settings are either not implemented or implemented with errors.  

A lack of encryption and security misconfiguration is easily determined by the employees of an organization. It may cause a potential threat to the organization by stealing all its personal and confidential information that harms the whole institution or organization.

Therefore, it is possible for the person to determine the lack of Encryption and Security Misconfiguration in an organization.

To learn more about Security misconfiguration, refer to the link:

https://brainly.com/question/29095078

#SPJ1

Many documents use a specific format for a person's name. Write a program that reads a person's name in the following format:

firstName middleName lastName (in one line)

and outputs the person's name in the following format:

lastName, firstInitial.middleInitial.

Ex: If the input is:

Pat Silly Doe
the output is:

Doe, P.S.
If the input has the following format:

firstName lastName (in one line)

the output is:

lastName, firstInitial.

Ex: If the input is:

Julia Clark
the output is:

Clark, J.

Answers

Using the knowledge in computational language in JAVA it is possible to write the code that write a program whose input is: firstName middleName lastName, and whose output is: lastName, firstName middleInitial.

Writting the code:

import java.util.Scanner;

import java.lang.*;

public class LabProgram{

public static void main(String[] args) {

String name;

String lastName="";

String firstName="";

char firstInitial=' ',middleInitial=' ';

int counter = 0;

Scanner input = new Scanner(System.in);

name = input.nextLine(); //read full name with spaces

int i;

for(i = name.length()-1;i>=0;i--){

if(name.charAt(i)==' '){

lastName = name.substring(i+1,name.length()); // find last name

break;

}

}

for(i = 0;i<name.length()-1;i++){

if(name.charAt(i)==' '){

firstName = name.substring(0, i); // find firstName

break;

}

}

for(i = 0 ;i<name.length();i++){

if(name.charAt(i)==' '){

counter++; //count entered names(first,middle,last or first last only)

}

}

if(counter == 2){

for(i = 0 ;i<name.length();i++){

if(Character.toUpperCase(name.charAt(i)) == ' '){

middleInitial = Character.toUpperCase(name.charAt(i+1));//find the middle name initial character

break;

}

}

}

firstInitial = Character.toUpperCase(name.charAt(0)); //the first name initial character

if(counter == 2){

System.out.print(lastName+", "+firstName+" "+middleInitial+".");

}else{

System.out.print(lastName+", "+firstName);

}

}

}

See more about JAVA at brainly.com/question/12975450

#SPJ1

Write the following short piece of code in python:

Answers

Programmers refer to a brief section of reusable source code, machine code, or text as a “snippet.” These are typically explicitly defined operational units that are integrated into bigger programming modules.

What are the short piece of code in python?

Guido van Rossum created Python, an interpreted, object-oriented, high-level programming language with dynamic semantics. It was first made available in 1991.

The syntax of Python is straightforward and resembles that of English. Python's syntax differs from various other programming languages in that it enables programmers to construct applications with fewer lines of code.

Therefore, Python operates on an interpreter system, allowing for the immediate execution of written code. As a result, prototyping can proceed quickly.

Learn more about python here:

https://brainly.com/question/10718830

#SPJ1

Welcome to Gboard clipboard, any text that you copy will be saved here.​

Answers

Answer: Welcome to Gboard clipboard, any text you copy will be saved here.

Secure websites use technology that scrambles the information you send. This is known as
A. hacking.
B. encryption.
C. padlocking.
D. digital media.

Answers

Answer:

B. Encryption.

Explanation:

Encryption encrypts data so that it can not be understood if/when it is intercepted by a third party between the sender and the recipient.

For example, if you're encrypting via the keyword vanilla, and then sending an email to Bob saying "Hi Bob", it would get encrypted as something like Vjh D5xx. The recipient would then use the keyword vanilla to decrypt this message so they can read it as Hi Bob. Anyone who intercepts this wouldn't have the keyword, and would just see incoherent letters, numbers, and symbols that they couldn't make heads or tails of.

Secure websites use technology that scrambles the information you send. This is known as, Encryption. So, the correct option is B.

Given that,

Secure websites use technology that scrambles the information you send.

Since, Secure websites use encryption technology to scramble the information you send, ensuring that it remains secure and protected during transmission.

Encryption involves the use of mathematical algorithms to transform data into an unreadable format, making it extremely difficult for unauthorized parties to access or understand the information.

This is a fundamental method used to safeguard sensitive data on the internet.

So, Option B is true.

To learn more about Encryption visit:

https://brainly.com/question/30408255

#SPJ6

Identification where Information Technology is not present to support business processes

Answers

Identification where Information Technology is not present to support business processes is one that   Lacking an IT implementation Plan.

What is the importance of information technology planning?

The accomplishment of the organization's strategic goals and objectives can be helped by this planning.

Note that  the strategic IT plan should include changes that will be required to the organization's information and communications infrastructure as well as the relevance of technology to each of the organization's strategic business goals.

Therefore,  business process would find it difficult to run efficiently without fully functional computers and access to emails and data.

Learn more about business processes from

https://brainly.com/question/14476382
#SPJ1

Carlos is studying human skin cells under a microscope during science class. He asks his teacher why cells are small. Which response does his teacher give him?

Answers

Since Carlos is studying human skin cells and he asks his teacher why cells are small. The response that his teacher give him will be: Larger cells could not efficiently transport nutrients.

Why are big cells not productive?

The plasma membrane won't have enough surface area if the cell enlarges too much to support the rate of diffusion needed to accommodate the larger volume. In other words, a cell gets less effective as it develops.

Any of the four major cell types that make up the epidermis may be referred to as "skin cells." These are the Langerhans cells, Merkel cells, keratinocytes, and melanocytes.

Note that Because there is less plasma membrane and a longer distance for molecules to travel, a large cell has more volume and is less effective at moving items into, out of, and through the cell. The cell needs its supplies to be received and transferred in a timely manner for many of its organelles.

Learn more about human skin cells from

https://brainly.com/question/27132976
#SPJ1

What does it mean to say,"we are in a post-PC world?"

Answers

Answer:

The use of mobile devices rather than only desktop computers for games, Internet access, general computing and as a terminal to the corporate network. We are in the post-PC era today.

1. Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type dayType:

a. Set the day.
b. Print the day.
c. Return the day.
d. Return the next day.
e. Return the previous day.
f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
Add the appropriate constructors.

2. Also, write a program to test various operations on this class .

Answers

Using the knowledge in computational language in C++ it is possible to write the code that design and implement a class dayType that implements the day of the week in a program.

Writting the code:

#include "stdafx.h"

#include<iostream>

#include<cmath>

sing namespace std;

class dayType

{

public: int presday;

int prevday;

int nextday;

dayType()

presday = 0;

nextday = 0;

prevday = 0;

}

void set(int day); //function declarations

void print(int day);

int Next_day(int day);

int day();

int prev_day(int pres);

};

void dayType::set(int day) //member functions

{

presday = day;

}

/* modify here*/

int dayType::prev_day(int day)

{

prevday = presday - day;// =abs(presday-day);

if (prevday<0)prevday += 7;

return prevday;

}

int dayType::day()

{

return presday;

}

int dayType::Next_day(int day)

{

nextday = presday + day;

if (nextday>7)

{

nextday = nextday % 7;

}

return nextday;

}

void dayType::print(int d)

{

if (d == 1)

cout << "Monday" << endl;

if (d == 2)

cout << "Tuesday" << endl;

if (d == 3)

cout << "Wednesday" << endl;

if (d == 4)

cout << "Thursday" << endl;

if (d == 5)

cout << "Friday" << endl;

if (d == 6)

cout << "Saturday" << endl;

if (d == 7)

cout << "Sunday" << endl;

}

/* here modify change void to int type */

int main()

{

int d, p, n;

dayType obj;

cout << "1-Mon" << endl << "2-Tue" << endl << "3-Wed" << endl << "4-Thur" << endl << "5-Fri" << endl << "6-Sat" << endl << "7-sun" << endl;

cout << "Enter Day";

cin >> d;

obj.set(d);

cout << "Present day is";

obj.print(d);

cout << "Enter number of days next";

cin >> d;

n = obj.Next_day(d);

cout << "Next day is";

obj.print(n);

cout << "Enter number of days previous";

cin >> d;

p = obj.prev_day(d);

cout << "previous day is";

obj.print(p);

system("Pause");

return 0;

}

See more about C++ at brainly.com/question/29225072

#SPJ1

How many subnets and host per subnet are available from network 192.168.43.0 255.255.255.224?

Answers

It is to be noted that from network 192.168.43.0 255.255.255.224 the number of subnets and hosts available are 8 and 32 respectively. Out of the 32 hosts only 30 are usually usable.

What is a host in networking?

A computer or other device linked to a computer network is referred to as a network host. A host can function as a server, providing information resources, services, and programs to network users or other hosts. At least one network address is assigned to each host.

A computer network is a collection of computers that share resources that are located on or provided by network nodes. To interact with one another, the computers employ standard communication protocols across digital linkages.

So with regard to the above answer, note that by entering the data into an online IPv4 subnet calculator, we are able to arrive at the total number of:

8 subnets; and 30 hosts available for 192.168.43.0 (IP Address) and 255.255.255.224 (Subnet)

Learn more about Subnets:
https://brainly.com/question/15055849
#SPJ1


Create a loop to display all even numbers from 0 to 100. Describe the three elements that must be included in order for a loop to
perform correctly. What will happen if these statements are not included? Provide examples.
The three elements that must be included in order for a loop to perform correctly. What will happen if these statements are not included? Provide examples

Answers

A loop to display all even numbers from 0 to 100:

for(i= 0;i<= 100; i++) {  

       if(counter%2 == 0) {

           printf("%d ",i);

The loop consists of three important parts:

the initialization: the keyword that starts the loopthe condition: the condition being testedthe update: for each iteration.

By missing a condition statement in a for loop, it would loop forever.

Example:

void main() {  

int i = 10;

for( ; ;) {

printf("%d\n",i); }

}

As in the above code, the for loop is running for infinite times and printing the i value that is 10 infinitely.

What is a for loop used for?

A "For" Loop is used to repeat a specific block of code a known number of times.

What are the main types of loops?

There are two types of loops, “while loops” and “for loops”. While loops will repeat while a condition is true, and for loops will repeat a certain number of times.

What are the elements of a loop?

Loop statements usually have three components: initialization, condition, and update step, and it contains a loop body.

To know more about loop:

https://brainly.com/question/16922594

#SPJ1

Consider this program on the picture attached:
(a) In what programming language is this program implemented?
(b) Why is this program correct? In other words, how does it work?
(c) In what way is the program poorly designed?

Answers

a) javascript (or Ecmascript if you’re fancy like that)

b) the program assigns the immutable variable “arr” to an array of intagers. It then iterates over the items of the array starting at index zero. The current value is declared as “item”. It will then print item cast as a string to the console.

c) this program is poorly designed due to the use of “SetTimeout”. During each iteration, the program will await item milliseconds before printing the item to the console. This affects the speed of the program due to thread sleeps every iteration

Write an SQL statement to display for every restaurant the name of the restaurant (where the name of the restaurant consists of more than 10 characters) and for every category of menu item its description (catdesc). Furthermore, display the average; cheapest or lowest; and highest or most expensive price of all menu items in that category at that restaurant. Use single row functions to format all the prices. The average price must be padded; the cheapest price must be rounded; but the highest price must not be rounded. Display only those menu items of which the average item price is more than R40. Sort your results according to the restaurant names and for every restaurant from the most expensive average menu item to the cheapest average menu item. Display your results exactly as listed below.

Answers

Using the knowledge in computational language in SQL it is possible to write the code that display for every restaurant the name of the restaurant  and for every category of menu item its description.

Writting the code:

INSERT INTO Dish Values(13, 'Spring Rolls', 'ap');

INSERT INTO Dish Values(15, 'Pad Thai', 'en');

INSERT INTO Dish Values(16, 'Pot Stickers', 'ap');    

INSERT INTO Dish Values(22, 'Masaman Curry', 'en');  

INSERT INTO Dish Values(10, 'Custard', 'ds');  

INSERT INTO Dish Values(12, 'Garlic Bread', 'ap');    

INSERT INTO Dish Values(44, 'Salad', 'ap');    

INSERT INTO Dish Values(07, 'Cheese Pizza', 'en');  

INSERT INTO Dish Values(19, 'Pepperoni Pizza', 'en');    

INSERT INTO Dish Values(77, 'Veggie Supreme Pizza', 'en');

INSERT INTO MenuItem Values(0, 0, 13, 8.00);

INSERT INTO MenuItem Values(1, 0, 16, 9.00);

INSERT INTO MenuItem Values(2, 0, 44, 10.00);

INSERT INTO MenuItem Values(3, 0, 15, 19.00);

INSERT INTO MenuItem Values(4, 0, 22, 19.00);

INSERT INTO MenuItem Values(5, 3, 44, 6.25);

INSERT INTO MenuItem Values(6, 3, 12, 5.50);

INSERT INTO MenuItem Values(7, 3, 07, 12.50);

INSERT INTO MenuItem Values(8, 3, 19, 13.50);

INSERT INTO MenuItem Values(9, 5, 13, 6.00);

INSERT INTO MenuItem Values(10, 5, 15, 15.00);

INSERT INTO MenuItem Values(11, 5, 22, 14.00);

See more about SQL atbrainly.com/question/13068613

#SPJ1

Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutes ToMiles().
Original main):
int main()
double milesPerHour;
double minutesTraveled;
double hoursTraveled;
double milesTraveled;
cin >> milesPerHour;
cin >> minutesTraveled;
hoursTraveled minutesTraveled / 60.0;
milesTraveled - hoursTraveled * milesPerHour;
cout ‹< "Miles:
<< milesTraveled ‹‹ endl;
return 0;

Answers

#include <iostream>

double mph_and_minutes_to_miles(double mph, double min) {

   return mph*double(min/60);

}

int main(int argc, char* argv[]) {

   double imph, imin; std::cin>>imph>>imin;

   std::cout << "Miles: " << mph_and_minutes_to_miles(imph,imin) << std::endl;

   return 0;

}

PLEASE answer me quick its due tomorrow so please answer


- What is a Computer Network?

- What is the concept of Internet of things (IOT)?

- What are the elements of a Smart Object?

- Explain the the concept of Micro-Controller.

Answers

A computer network is a collection of computers that share resources that are located on or provided by network nodes. To interact with one another, the computers employ standard communication protocols across digital linkages.

The Internet of Things refers to physical items equipped with sensors, processing power, software, and other technologies that communicate and share information with other devices and processes over the Internet or other network infrastructure.

Sensors, microprocessors, storage systems, controls, programming, and embedded system software with enhanced user interface make up a smart object.

A microcontroller is a small integrated circuit that controls a single function in an embedded system. On a single chip, a typical microcontroller has a CPU, memory, and input/output (I/O) peripherals.

All the above are part of computer architecture.

What is computer architecture?

Computer architecture is a collection of principles and procedures used in computer engineering to explain the functioning, structure, and deployment of computer systems. A system's architecture refers to its structure in terms of individually stated components and their interrelationships.

The hardware, system software, and user layers comprise computer architecture.

Learn more about computer networks:
https://brainly.com/question/14276789
#SPJ1

Can someone help me out with a code. Code's in python write a function that returns the longest common prefix of two strings. For example, the longest
common prefix of distance and disinfection is dis. The header of the method is:
def prefix(s1, s2)
If the two strings have no common prefix, the method returns an empty string.
Write a main function that prompts the user to enter two strings and displays their common
prefix.
here's what I have currently but its not working.
def longestCommonPrefix(self, arr):

arr.sort(reverse = False)
print(arr)
n= len(arr)
str1 = arr[0]
str2 = arr[n-1]

n1 = len(str1)
n2 = len(str2)
result = ""
j = 0
i = 0

while(i <= n1 - 1 and j <= n2 - 1):
if (str1[i] != str2[j]):
break
result += (str1[i])

i += 1
j += 1

return (result)

Answers

Just 10 lines of code.

from functools import reduce

list = []

def compare():

   calc = [reduce(lambda a, b: a if a == b else None, x) for x in zip(*list)] + [None]

   return list[0][:calc.index(None)]

   

list.append(input("Enter the first string: "))

list.append(input("Enter the second string: "))

print(compare())

Other Questions
Which number is greatest? 24/100 0.3 16% jeanine is planning on making her first million dollars before she reaches 25 years of age. though still in high school, she subscribes to the wall street journal, carries a brief case, and invests her allowance with a stockbroker. moreover, she insists on wearing business suits everyday to school. jeanine is thoroughly engaged in: HELPP!!! Write a system of equations to describe the situation below, solve using substitution, and fill in the blanks. A business owner wants to have the front window of her store painted and is considering two artists for the job. Grace has quoted a flat rate of $99 for the job. Eva's quote is $10 per hour, plus $89 to cover the cost of materials. Depending on how long it takes Eva to paint the window, these two could end up charging the same amount. How much would it cost? How long would Eva have to take? You hav Vide what causes the different numbers between a master budget and a flexible budget? a. sales price. b. fixed costs. c. input price. d. sales volume. according to the ife, if british interest rates are lower than u.s. interest rates a. the british pound will depreciate against the dollar. b. the british inflation rate will decrease. c. the british pound will appreciate against the dollar. d. today's forward rate of the british pound will equal today's spot rate. e. the british pound's value will remain constant. The 1st term of a certain sequence is -10, and the 2nd term is 1. Each subsequent term is obtained by adding the 2 immediately preceding terms. What Is the 5th term of this sequence? An 80kg woman jumps from a wall and lands stiff-legged in soft sand. The woman's downward speed just as she touches the sand is 6m/s. She is stopped after sinking 0.05m into the sand. Calculate the net force on the woman while she is being stopped by the sand. Round to nearest whole number Select all the differences between DNA and RNA. aRNA contains one strand of nucleotides, and DNA has two. bDNA contains two strands of nucleotides, and RNA has four. cIn RNA, thymine is replaced by uracil. dDNA is contained only within the nucleus and RNA is not. eRNA is more complex than is DNA because of its multiple forms. fIn DNA, guanine is replaced by uracil. US HistoryPlease help ASAP What is the fastest speed a tennis ball can cross the net horizontally and still land in the court? from the net to the end line is 12 m, and the height of the net is 1 m. neglect air resistance and spin of the ball. A number is 2 times another number. If the larger number is increased by 14, the result is 4 less than 4 times the smaller number. O Points: 0 ofA medical research study on a new medicine for multiple sclerosis is being conducted with 24 patients. After the study was concluded, itmedicine, 7 reacted unfavorably, and 2 were unaffected. If three of the patients are randomly selected, determine the probability that nor Which file format produces smaller files by eliminating some information from the file?. a 1500 kg vehicle is traveling on a curved, icy road. the road is banked at an angle of 10.0 degrees and has a radius of curvature of 400 m. the velocity of the car necessary to travel on the icy road without sliding is . Approximately 72% of persons living in Cape Town who are aged 70 to 84 live in elderly care facilities. If four persons are randomly selected from this population, what is the probability that exactly two of the four live in elderly care facilities?Select one: Which formula is used to find the growth rate of a population? O Death rate - Birth rate = Growth rate O Death rate x Birth rate= Growth rate O Birth rate - Death rate= Growth rate O Death rate + Birth rate = Growth rate Solve for x. Show your work, and give exact answers where possible. Otherwise, round to the nearest hundredth. select all that apply select all the statements that correctly describe steps in the procedure used to identify a limiting reactant. multiple select question. the maximum product possible is given by the sum of the amounts of product formed from each reactant. the reactant that produces the least amount of possible product is the limiting reactant. the reactant that has the highest mass at the beginning of the reaction is in excess. calculate the molar masses of any reactants for which a mass has been given. calculate the amount of product that could be formed from each reactant. use a table to list problems facing the south after the civil war and at least one attempted solution for each problem crest, has decided to introduce its 1-hour express whitening strips in four cities and to closely monitor the reactions of consumers to the product and marketing program. crest is going to use: