1. Using logical operators modify the following Python "if" statement to print ("AND operator condition worked")?
x=2
y=3
if (x<=2 or y>=3) and (x>2 or y<2):
print("AND operator condition worked")
else: print("it doesn't work")
2. Write a program that asks user for five numbers and returns the largest of them. Do not use max function built in python.
x=2 y=3 if (x<=2 or y>=3): print("AND operator condition worked") else: print("it doesn't work")
AND operator condition worked
lst = [] for x in range(5): lst.append(eval(input("Enter number "+str(x)+": "))) maxVal = lst[0] for x in lst: if(maxVal < x): maxVal = x print("Max value =",maxVal)
1. Using logical operators modify the following Python "if" statement to print ("AND operator condition worked")?...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.
s1 = 'Practice How to Use String Object' Write a python statement that splits the string, creating the following list: ['Practice', 'How', 'to', 'Use', 'String', 'Object'] 2. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’: reply = input("Y or y to continue: ") if reply == "Y" and reply == "y": print("Y --- <uppercase> has been selected. ") else: print("y --- <lowercase> has been chosen. ") print("… continue...
computer Programming visual Basic 1-10 QUESTION 1 Which of the following is not a logical operator in Visual Basic? Not • or And Then QUESTION 2 Which of the following is a valid Visual Basic conditional statement? 2<n<5 2 <n or <5 0 2 <n<5 (2 <n) or (n <5) QUESTION 3 When Visual Basic stops evaluating a compound condition with the logical And operator because the first condition evaluates to False. It is called evaluation. short-circuit Pre- compound first...
USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...
10) you will run/call the function with these given values. (b) Write a flow chart and the script file using conditional statements with logical operator if/else and if/elseif, to evaluate the following function, assuming that the scalar x has a value: y 2 sin(m) for-1 x < 5 y=10(X-5) + 1 for x 25 Use your file to evaluate y for x5,x 3 and x 15 by hand 10) you will run/call the function with these given values. (b) Write...
Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word) To run the function modify() defined above, we make the following call: result = modify('course', 's') Find and fix the errors in the function definition, lines (1) to (4), such that after the call is executed: • Variable result has the value 'courses' • 'new word is courses' is printed out. For each error found and fixed, you must indicate the following: • line...
Write, save, and run a Python program that will do the following when run: Let’s consider the following assignment: a = 1 * 2 + 38 / 8 You want to change the precedence of the operators so that the addition operations are executed first. How would you re-write the assignment? Write a print statement to show the output. Let’s consider the following assignments: x = 'z' y= ['x', 'z', 'q'] Now, apparently x is a member of y. Write...
using mips for assembly language WPte a program that asks the user for 2 numbers. the program should then add the 2 numbers bit by bit, using boolean operators no arithmetic operations ex: add, addi, sub, mult, div or arrays are permitted in this project. forming a new variable (in a register) with the solution. That solution is to be output bit by bit using the function that was written in class do not use syscall with a value 10...
in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){ sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() { int score, highest; //missing portion of the program return 0; } 1(c). Find the missing portion of the following code, so the...