who can help me looping
Answer:
See attachment
Explanation:
I have provided all 3 programs in the attached text file.
All of these are complete programs so I could test them myself
Hope that works for you
The value of the expression X(X+Y) is X
O a. True
b. False
sorry I didn’t know this was Boolean math
I answered for regular math equations
You have multiple manufacturing computers that control the machinery to several assembly lines. The software for the assembly line controls rarely changes. The assembly lines cannot go down because of problem Windows updates or new features.
Q. What do you recommend?
Since the assembly lines cannot go down because of problem Windows updates or new features, I would recommend that the automatic update of Windows should be turned OFF or limited to essential updates only.
What is an operating system?An operating system (OS) is a system software that's usually pre-installed on a computing device by the manufacturers, so as to manage random access memory (RAM), software programs, computer hardware and all user processes.
In Computer technology, some examples of an operating system used on various computers include the following:
OpenVMSMacOSQNX OSLinux OSIBMSolarisVirtual Machine (VM)Microsoft Windows OSGenerally speaking, we know that the software used on manufacturing computers in the assembly line controls rarely changes and as such to prevent the assembly lines from going down due to issues associated with Windows updates or new features, I would recommend that automatic update and new features of Windows should be disabled, turned OFF or limited to essential updates only.
Additionally, Windows 10 Enterprise Long-Term Servicing Branch (LTSB) can also be installed to solve this problem.
Read more on Windows updates here: https://brainly.com/question/15329847
#SPJ1
computational thinking
Answer:
Computational Thinking (CP) is the mental skill to apply fundamental concepts and reasoning, derived from computing and computer science, to solve problems in all areas.
modem is used for what?
Answer: Its a device
Explanation:
Basically it goes through a coax cable that connects through your home and gives you internet.
Answer:
A modem is a device that connects your home, usually through a coax cable connection, to your Internet service provider (ISP), like Xfinity. The modem takes signals from your ISP and translates them into signals your local devices can use, and vice versa.
Explanation:
Brainlest, Please!
Instructions
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
For example, it should output the individual digits of:
3456 as 3 4 5 6
8030 as 8 0 3 0
2345526 as 2 3 4 5 5 2 6
4000 as 4 0 0 0
-2345 as 2 3 4 5
My code:
#include
using namespace std;
int main(int argc, char* argv[]){
// Write your main here
int a=0,b[100]={0},n=0,sum=0;
cin>>a;
while(a>0)
{
b[n]=a%10;
a/=10;
n++;
}
for(int i=n; i>0; i--)
{
printf("%d ",b[i-1]);
sum+=b[i-1];
}
printf(" Sum: %d ",sum);
cin.get(); cin.get();
return 0;
}
Problem:
The input needs to be -2345
and the output should result in
Sum: 0
but it's wrong,
the result of this code is 50%
and I don't know why, pls help
A program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits is given below:
The Program#include < iostream >
int main( int argc , char * argv [ ] )
{
int number , digit , sum = 0;
std : : cout < < " Enter number : " ;
std : : cin > > number ;
while ( number > 0 )
{
digit = number % 10;
std : : cout << digit << ' \ t ' ;
sum = sum + digit ;
number = number / 10 ;
}
std : : cout < < " Sum is : " < < sum < < std : : endl ;
return 0;
}
Your original code has the right ideas, but you will have to use the std to print out the output as used above and your output would be in individual numbers.
Read more about programming here:
https://brainly.com/question/23275071
#SPJ1
Hello, I desprately need help in python with this question. I have tried everything:This is the question:
4.19 LAB: Driving costs - functions
Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:.2f}'.format(your_value))
Ex: If the input is:
20.0
3.1599
the output is:
1.58
7.90
63.20
Your program must define and call the following driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles.
Ex: If the function is called with:
50 20.0 3.1599
This is my code:
miles_per_gallon = float(input('miles_per_gallon: '))
dollars_per_gallon = float(input('dollars_per_gallon: '))
dollars_per_mile = dollars_per_gallon/miles_per_gallon
your_value1 = 10 * dollars_per_mile
your_value2 = 50 * dollars_per_mile
your_value3 = 400 * dollars_per_mile
print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3))
Can someone tell me what I'm doing incorrectly or show me? Thanks truly.
Lily
Answer:
Code is below and also attached in text file
Explanation:
Because Python indentation is extremely important and pasting code in the brainly window sometimes messes it up, I have provided code below as well as in the attached text file. If the one below works, well and good. Otherwise use the one in the text file
Let me know if you have questions
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
'''
Equations Used:
gallons_consumed = driven_miles/miles_per_gallon
dollar_cost = gallons_consumed x dollars_per_gallon
'''
gallons_consumed = driven_miles/miles_per_gallon
dollar_cost = gallons_consumed * dollars_per_gallon
return dollar_cost
# Get inputs from the user
miles_per_gallon = float(input('miles_per_gallon: '))
dollars_per_gallon = float(input('dollars_per_gallon: '))
print()
#Compute dollar cost by calling the driving_cost function
for miles_driven in [10, 50, 400]: #iterate through the list of miles
cost = driving_cost(miles_driven, miles_per_gallon, dollars_per_gallon) #call function
print("{:.2f}".format(cost))
Translate the following C program to Pep/9 assembly language.
#include
int myAge;
void putNext(int age) {
int nextYr;
nextYr = age + 1;
printf("Age: %d\n", age);
printf("Age next year: %d\n", nextYr);
}
int main () {
scanf("%d", &myAge);
putNext(myAge);
putNext(64);
return 0;
}
In this exercise we have to use the knowledge of computational language in C code to write a code that Translate the following C program to Pep/9 assembly language.
Writting the code:In C code:#include <stdio.h>
int myAge;
void putNext(int age) {
int nextYr;
nextYr = age + 1;
printf("Age: %d\n", age);
printf("Age next year: %d\n", nextYr);
}
int main () {
scanf("%d", &myAge);
putNext(myAge);
putNext(64);
return 0;
}
In Pep 9 CODE-myAge:
.zero 4
.LC0:
.string "Age: %d\n"
.LC1:
.string "Age next year: %d\n"
_Z7putNexti:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movl %edi, -20(%rbp)
movl -20(%rbp), %eax
addl $1, %eax
movl %eax, -4(%rbp)
movl -20(%rbp), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
movl -4(%rbp), %eax
movl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
nop
leave
ret
.LC2:
.string "%d"
main:
pushq %rbp
movq %rsp, %rbp
movl $myAge, %esi
movl $.LC2, %edi
movl $0, %eax
call scanf
movl myAge(%rip), %eax
movl %eax, %edi
call _Z7putNexti
movl $64, %edi
call _Z7putNexti
movl $0, %eax
popq %rbp
ret
See more about C code at brainly.com/question/18502436
#SPJ1
Which of the following refers to an attempt to compromise a device by gaining unauthorized access? A. infecting a computer with a virus B. hacking C. using quotation marks in a search engine D. sending malware
The option that refers to an attempt to compromise a device by gaining unauthorized access is option B. hacking.
What is meant by hacking?In the context of digital devices like computers, smartphones, as well as tablets, and even entire networks, hacking refers to actions that aim to breach those systems.
Note that Hackers are driven by monetary gain, the desire to make a statement, or simply the want to do anything.
Therefore, hacking is illegal as it is a felony that is committed every time someone enters a computer without authorization, even if they don't take anything or harm the system.
Learn more about hacking from
https://brainly.com/question/23294592
#SPJ1
100 POINTS! What are the essential parts of a mathematical function in spreadsheets? Select three options.
A. input parameters
B. variables
C. output value
D. expressions
E. name
Answer:
D.
Explanation:
It is to be noted that the essential parts of a mathematical function in spreadsheets are:
input parameters (Option A)variables (Option B)expressions (Option D).What is a mathematical function?A mathematical function is a rule that determines the value of a dependent variable based on the values of one or more relationships between the independent variable. A function can be represented in a variety of ways, including a table, a formula, or a graph.
When it comes to variables and spreadsheets, "it's garbage in garbage out." The computer has no way of knowing which variable is the right one to enter. This remains the solve prerogative of the Spreadsheet user, hence it's importance.
Learn more about Spreadsheets:
https://brainly.com/question/26919847
#SPJ1
Answer must be submitted in a python file (.py at the end of the file) or as python code snippet
Pretend you need to added 10% taxes to your total from a purchase
Write a program that answers this questions (What is your total?) using the input function
Take the value entered and add 10% to the total
Display the total
Answer:
purchase_cost = float(input("What is your purchase cost? "))
tax_rate = 10/100 #(10% = 10/100)
tax = purchase_cost * tax_rate
total_cost = purchase_cost + tax
print("Total Cost = ", total_cost)
Explanation:
why do we need to have multiple image file format
Answer:
Explanation:
Each format represents a particular way of storing the data that makes up a file.
What is the output of the below Python code?
list1=[12,54,32,29,81]
list1.remove(32)
print(list1)
The output of the below Python code:
list 1 = [ 12, 54 , 32 , 29 , 81 ]
list 1 . remove ( 32 )
print ( list1 )
is
[12, 54, 29, 81]
What is a List in Python Programming?This refers to the sequence that contains python objects and objects inside are separated by a comma (,) and enclosed within square brackets.
Hence, it can be noted that:
A List can contain values of the types Integers, Floats, Lists, and Tuples.
Integer values such as the whole numbers can be positive, negative, and zero. Example => 5, 6, 7, -8, 0 etc.
Float values are those values that consist of decimal numbers. Example => 5.25, 9.187 etc
Therefore, we can see that from the given code:
list1 is a list and it contains integers.
list1.remove(32) removes the first matching element 32
After all the compiling is done, the output would be [12, 54, 29, 81]
Read more about programming here:
https://brainly.com/question/23275071
#SPJ1
which encryption protocol does gre use to increase the security of its transmissions?
Utilizing IPsec for security during transmission is the encryption protocol used to strengthen the security of its transmissions. The right answer is c.
The encryption algorithm performs encryption. To perform encryption, encryption algorithms are utilized. These algorithms use the encryption key to carry out all cryptographic operations on the plaintext material. These methods are then used in encryption protocols to protect data for a number of objectives. A security protocol (also known as a cryptography protocol or encryption protocol) is a concrete or abstract protocol that carries out a security-related task while also employing cryptographic techniques, frequently in the form of sequences of cryptographic primitives. As a result, the encryption protocol to boost security is IPsec, which is option c.
The complete question- Your most probably complete question is given below:
a. SSL b. SFTP c. IPsec d. SSH.
Learn more about protocol here-
https://brainly.com/question/27581708
#SPJ4
3) Which of the following would not impact the digital divide?
Expansion of free wifi connectivity in major cities
O Legislation allowing communications companies to charge per website for access
O Less sharing of the work we produce
O A decline in the price of internet access
The statement which does not impact the digital divide is Less sharing of the work we produce. Thus the correct option is C.
What is the Digital divide?The term "digital divide" refers to the imbalance in populations and geographical locations between those who have and or without limited access to contemporary information and communications technology
Less sharing of work we produce does not impact the digital divide as Internet connectivity and wireless connectivity like Wi-Fi are frequently unavailable due to the digital divide.
Therefore, option C is appropriate.
Learn more about the digital divide, here:
https://brainly.com/question/13151427
#SPJ1
Can someone help me with a code
Write a program that generates and prints five random lottery numbers of a three-digit number
between 100 and 999. The three digits in the number are the same. Use only one loop.
it needs to print what's below.
Lottery number1: 333
Lottery number2: 222
Lottery number3: 888
Lottery number4: 777
Lottery number5: 111
Answer:
lottery number 3
Explanation:
Ask the user to input an integer. Print out the three numbers before it.
Sample Run-
Enter an integer: 4
3
2
1
Answer:
f=float(input("Enter an integer: "))
c=(f-1)
a=(c-1)
b=(a-1)
print(str(c))
print(str(a))
print(str(b))
Explanation:
This will print everything correctly, just copy and paste!
Questions about Python or more ProjectStem help? Just Send me a message!
what am i doing wrong ????
def main():
firstNumber = float(input('Enter your first number'))
secondNumber = float(input('Enter your second number'))
return firstNumber, secondNumber
def add(firstNumber ,secondNumber):
return firstNumber + secondNumber
def subtract(firstNumber , secondNumber):
return firstNumber - secondNumber
def multipy (firstNumber , secondNumber):
return firstNumber * secondNumber
def divide (firstNumber, secondNumber):
return firstNumber / secondNumber
def modulo (firstNumber , secondNumber):
return firstNumber % secondNumber
def exponent (firstNumber , secondNumber):
return firstNumber ** secondNumber
def userOutput(firstNumber, secondNumber,total,sub,mul,div,mod,exp):
print(firstNumber + secondNumber == total)
print(firstNumber - secondNumber == Sub)
print (firstNumber * secondNumber == mul)
print (firstNumber / secondNumber == div)
print (firstNumber % secondNumber == mod)
print (firstNumber ** secondNumber == exp)
total = add(firstNumber , secondNumber)
sub = subtract(firstNumber, secondNumber)
mul = multiply(firstNumber, secondNumber)
div = divide(firstNumber, secondNumber)
mod = modulo(firstNumber, secondNumber)
exp = exponent(firstNumber, secondNumber)
def printAnswer (anwserAdd, anwserSubtract,anwserMultiply,anwserdivide, anwserModulo,anwserExponent):
print (anwserAdd, anwserSubtract,anwserMultiply,anwserdivide, anwserModulo,anwserExponent)
# --------------------------------
# I've called main() for you.
# This line is a special way to call main
# that allows me to test your code. Do not change it!
if __name__ == '__main__':
main()
Explanation:
what is the problem ? does it not compile or run at all ? it do you get something unexpected ?
did you specify your whole program or just a part ?
based on what I see I would assume it does not compile and produce, so your cannot even start it.
and that should be because the way you defined printAnswer.
you did not specify types for the parameters, and because there is also no call of printAnswer, the compiler does not have any clue about the types that way either.
for userOutput this was different, because the return statements of all the functions (add, subtract, ...) provide the type information.
also, there is no end for the function printAnswer.
the compiler simply goes on after the print statement, assuming that the following still belongs to printAnswer and finds an if-starement checking a variable __name__, which might be unknown to the compiler (if there are no other definitions included at least in the background). and then a call of main.
and then finally printAnswer is finished.
further observations :
the print statements in userOutput clearly want to use strings, but you did not include any ' signs.
I think you meant them to look like
print(firstNumber, ' + ', secondNumber, ' == ', total)
our did you mean it as a user guideline for selecting or rather specifying an operation on the 2 numbers entered earlier ?
then it would be like
print('firstNumber + secondNumber == total')
then you never call printAnswer or userOutput anywhere. you don't ask for the user input anywhere to select the desired operation. and you don't check that input anywhere to define what operation to perform.
so, the main program will ask for the 2 numbers and then simply end.
What is wrong with the following JavaScript identifier? $the_value_1st_user_enters_for_a_name
An identifier cannot include underscores.
An identifier cannot include a reserved word (in this case, for).
An identifier cannot be more than 32 characters long.
Nothing is wrong with this identifier.
There is nothing wrong with the identifier that has been used in the JavaScript written in the question.
What is a JavaScript identifier?The term Java Script identifier is one that is used in Java script programming to talk about the characters that are in a capable that gave the ability of being able to identify variables as well as properties in functions.
These identifiers are known to be case sensitive. That is they are not to start with a digit and they are able to have unicodes such as the dollar sign.
What is a valid JavaScript Identifier?This is the term that is used to refer to an identifier in JavaScript that is known to include the underscore and is also made up of the dollar sign.
In the identifier that is presented in the question here, we can see that it is valid because it has the dollar sign and it also has the underscore in between the words.
Hence there is no issue with the identifier, Option D is correct as the solution.
Read more on JavaScript here:
https://brainly.com/question/7661421
#SPJ1
What are the differences
between scanning a 3-D object and photo-
graphing that same object with a camera?
Are there things you can control with a
camera that you cannot control with a
scanner?
The main difference between scanning a 3-D object and photographing that same object with a camera is that you can control the lighting when you scan an object, whereas you cannot control the lighting when you photograph an object. You can also control the distance between the object and the scanner, whereas you cannot control the distance between the object and the camera.
What is scanner?
Scanner is a disc space analysis and management utility for Microsoft Windows. It shows the disc space consumption of any drive or directory as a layered pie chart that can be browsed up and down the directory tree. When the mouse is moved over a pie, the application displays which directory the pie represents, how many files it contains, and how much disc space it takes up. A context menu allows users to open the directory in Windows Explorer, hide and unhide it from the diagram, and delete the pie from the disc permanently or via the Recycle Bin.
To learn more about scanner
https://brainly.com/question/24937533
#SPJ13
What is one of the FIRST things people at an advertising agency do when they are planning a new ad campaign?
A.
find the right images and symbols to get the message across
B.
decide which consumers they will target
C.
pick a new product name and a new slogan or catchphrase
D.
select the right music for the ad campaign
Answer: decide which consumers they will target
What does a computer code refer to, if I should take as a programming model a tree from nature? What exactly is the code supposed to do?
Computer code are said to be set of a defined instructions or a system of rules that are often defined in a specific programming language.
Coding informs a machine about a given actions to carry out and how to finish the tasks.
What does a programming code mean?Computer code are seen as some group of instructions and it is a term used in computer programming (such as the source code).
Therefore, Note that It is also the name given to the source code after a compiler has prepared it for computer execution (such as the object code).
Learn more about programming from
https://brainly.com/question/16936315
#SPJ1
The reduction of the amount of medication in the body can be modeled by
the equation , where A is the amount at time t, A0 is the amount at
t = 0, and k is the decay constant ( ). The half-life time of a certain
medication is 3.5 h. A person takes 400 mg of the medication at t=0, and
then additional 400 mg every 4 h. Determine the amount of the medication
in a patient’s body 23 h after taking the first dose.
After determining the value of k, define a vector
(the time since taking each dose) and calculate the corresponding values of
A. Then use MATLAB’s built-in function sum to determine the total
amount.
Answer:
hahahahahhahah
Explanation:
beacause nathonih
A contains elements that appear closest to the user, will have the best focus, and are meant to draw the most attention within design.
Answer:
Emphasis is the part of the design that catches the viewer's attention.
what's 7 // 2 result in python expression please
Explanation:
If the variable declared as float data type and stores the value(7/2) then the output will be 3.50. The decimal numbers is stored in float datatype.
I hope it will be helpful for you.
Answer: 3.50
Explanation: got it right on edgen
The code is working fine but I keep getting an EOF error on my 2nd last line.
program:
# option list for user choice
option = ['y', 'yes', 'YES', 'n', 'no', 'NO']
# invalid characters for hawaiian language
invalid_letters = {"b", "c", "d", "f", "g", "j", "q", "r", "s", "t", "v", "x", "y", "z"}
# dictionary for pronunciation of the letters of word
dictionary = {
'a' : 'ah',
'e' : 'eh',
'i' : 'ee',
'o' : 'oh',
'u' : 'oo',
'ai' : 'eye',
'ae' : 'eye',
'ao' : 'ow',
'au' : 'ow',
'ei' : 'ay',
'eu' : 'eh-oo',
'iu' : 'ew',
'oi' : 'oy',
'ou' : 'ow',
'ui' : 'ooey',
'p' : 'p',
'k' : 'k',
'h' : 'h',
'l' : 'l',
'm' : 'm',
'n' : 'n',
'w' : ['v', 'w']
}
# loop for user input
while option not in ['n', 'no']:
Alolan_word = input("Enter a hawaiian word: ").lower()
word = ' ' + Alolan_word + ' '
pronunciation = ''
skip = False
# loop for traversing the word by character wise
# match each character of word with elements of invalid_letters
for letter in Alolan_word:
if letter in invalid_letters:
print("Invalid word, " + letter + " is not a valid hawaiian character.")
break
# loop for scanning the accepted word letter wise
# match each letter of th word with corresponding pronunciation in the dictionary
for index in range(1,len(word)-1):
letter = word[index]
if skip:
skip = False
continue
if letter in {'p','k','h','l','m','n'}:
pronunciation += dictionary[letter]
if letter == 'w':
if word[index-1] in {'i','e'}:
pronunciation += dictionary[letter][0]
else:
pronunciation += dictionary[letter][1]
if letter == 'a':
if word[index+1] in {'i','e'}:
pronunciation += dictionary['ai'] + '-'
skip = True
elif word[index+1] in {'o', 'u'}:
pronunciation += dictionary['ao'] + '-'
skip = True
else:
pronunciation += dictionary[letter] + '-'
if letter == 'e':
if word[index+1] == 'i':
pronunciation += dictionary['ei'] + '-'
skip = True
elif word [index+1] == 'u':
pronunciation += dictionary['eu'] + '-'
skip = True
else:
pronunciation += dictionary[letter] + '-'
if letter == 'i':
if word[index+1] == 'u':
pronunciation += dictionary['iu'] + '-'
skip = True
else:
pronunciation += dictionary[letter] + '-'
if letter == 'o':
if word[index+1] == 'i':
pronunciation += dictionary['oi'] + '-'
skip = True
elif word [index+1] == 'u':
pronunciation += dictionary['ou'] + '-'
skip = True
else:
pronunciation += dictionary[letter] + '-'
if letter == 'u':
if word[index+1] == 'i':
pronunciation += dictionary['ui'] + '-'
skip = True
else:
pronunciation += dictionary[letter] + '-'
if letter in {"'", ' '}:
if pronunciation[-1] == '-':
pronunciation = pronunciation[:-1]
pronunciation += letter
if pronunciation[-1] == '-':
pronunciation = pronunciation[:-1]
# display the pronounciation of accepted word in hawaiian language
print(Alolan_word.upper() + " is pronounced " + pronunciation.capitalize())
option = input("Would you like to enter another word? [y/yes, n/no] ").lower()
print("All done.")
Answer:
Code is in the attached .txt file
Explanation:
It must have been an indentation error since I get good results using your code properly formatted. I am not sure what the original problem was so unable to comment further
You need to contact a client on the phone. You have estimated that you have a 70% chance of contacting the client on the first call. If you don't, you estimate that you have a 20% chance of contacting the client on a subsequent call in the next hour. Which of the following is true?
a. The probability that you will need at most two calls to contact the client is 0.90.
b. The probability that you will fail on call 1 but will succeed on call 2 is 0.06.
c. The probability that you will fail on call 1 but will succeed on call 2 is 0.50.
d. The probability that you will need at most two calls to contact the client is 0.80.
From the information provided, the correct answer is Option B - " The probability that you will fail on call 1 but will succeed on call 2 is 0.06." See further explanation below.
What is probability?Probability is an area of mathematics that deals with numerical representations of how probable an event is to occur or how likely a statement is to be true. The probability of an occurrence is a number between 0 and 1, where 0 denotes the event's impossibility and 1 represents certainty.
Hence,
P(E) = Number of favorable outcomes/Total Number of outcomes.
Step I
From the information provided, the probability of failing to contact the client on the first call can be computed as:
30% = 0.3
[Rationale is based on estimation. If there is an estimated 70% chance of success, then the chance of failure is 30% which is 0.3]
Step II
The probability of contacting the client on the second call is: 0.2 or 20% [Rationle is as per the given assumption.]
If the two scenarios above hold out because they are mutually exclusive events, the probability, therefore, that you will fial on call 1 and succeed on call two becomes:
0.3 x 0.2
= 0.06
Hence, Option B is the correct answer.
Learn more about probability:
https://brainly.com/question/25870256
#SPJ1
Lira has typed up a document and now she wants to adjust the irregular right edge of the text so that it is even. How can she accomplish this?
by changing the margins
by adjusting the indent markers
by changing the spacing between words
by using the Justify and Automatic Hyphenation options
ANSWER IS D. by using the Justify and Automatic Hyphenation options
Answer:
d. by using the Justify and Automatic Hyphenation options
Explanation:
A keyboarding technique, you can type more quickly and precisely without having to glance at the keyboard.
Answer: Look at the chart and use it to help you type, and eventually you'll get the hang of it.
Hello, I desperately need help in python with this question. I have tried everything: This is the question also:
4.24 LAB: Even/odd values in a list
Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers in the list. The first integer is not in the list.
Ex: If the input is:
5
2
4
6
8
10
the output is:
all even
Ex: If the input is:
5
1
-3
5
-7
9
the output is:
all odd
Ex: If the input is:
5
1
2
3
4
5
the output is:
not even or odd
Your program must define and call the following two functions. is_list_even() returns true if all integers in the list are even and false otherwise. is_list_odd() returns true if all integers in the list are odd and false otherwise.
def is_list_even(my_list)
def is_list_odd(my_list)
This is what I came up with:
def GetUserValues():
n = int(input())
numbers = []
for i in range(n):
numbers.append(int(input()))
return numbers
def IsListEven(myList):
for n in myList:
if n % 2 == 1:
return False
return True
def IsListOdd(myList):
for n in myList:
if n % 2 == 0:
return False
return True
if __name__ == '__main__':
userValues = GetUserValues()
if IsListEven(userValues):
print("all even")
elif IsListOdd(userValues):
print("all odd")
else:
print("not even or odd")
What Am I doing incorrectly and can someone show me?
Lily
Answer:
Read explanation and check out corrected code
Explanation:
Hi Lily
The formatting was destroyed when you copied pasted code onto the brainly question box.
When posting code, it's better to copy the code into a text editor(such as notepad), save it as a text file and upload this through the clip icon on the bottom right of the brainly toolbar (at the bottom)
Anyway, I copied your code and properly formatted it and it works fine
Since I cannot see the formatting, I am assuming that your return True statements are improperly indented. These statements should go with the for loop, not the if statement
Here is the wrong way to define
def IsListEven(myList):
for n in myList:
if n % 2 == 1:
return False
return True #this belongs to the if statement
If you write your code as follows, the return True goes with the if statement. That means it will return from the function as soon as it finds an even number without checking the rest of the list. For example if the list was [2, 4, 6, 8, 1], the function will return True on the first element in the list without going through all the elements
The correct way is:
def IsListEven(myList):
for n in myList:
if n % 2 == 1:
return False
return True # now belongs to the for loop
When posting code, it's better to copy the code into a text editor(such as notepad), save it as a text file and upload this through the clip icon on the bottom right of the brainly toolbar (at the bottom)
Why the code is copied?The copied your code and properly formatted it and it works fine. Since I cannot see the formatting, I am assuming that your return True statements are improperly indented. These statements should go with the for loop, not the if statement
Here is the wrong way to define
def IsListEven(myList):
for n in myList:
if n % 2 == 1:
return False
return True #this belongs to the if statement
If you write your code as follows, the return True goes with the if statement. That means it will return from the function as soon as it finds an even number without checking the rest of the list. For example if the list was [2, 4, 6, 8, 1], the function will return True on the first element in the list without going through all the elements
The correct way is:
def IsListEven(myList):
for n in myList:
if n % 2 == 1:
return False
return True # now belongs to the for loop
Therefore, When posting code, it's better to copy the code into a text editor(such as notepad), save it as a text file and upload this through the clip icon on the bottom right of the brainly toolbar (at the bottom)
Learn more about posting code on:
https://brainly.com/question/30390043
#SPJ2