logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Mahima VatsAccounting
(/5)

870 Answers

Hire Me
expert
Shilpi BhatnagarComputer science
(5/5)

857 Answers

Hire Me
expert
Christopher OchiengComputer science
(/5)

718 Answers

Hire Me
expert
Wyatt RyessEconomics
(5/5)

746 Answers

Hire Me
Probability
(5/5)

Write a program that checks if a number is positive, or negative, or zero.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Guide

Read the questions first. Try to solve as many as you can. Don't get stuck on a question.

Refer to the session notes and practice code Use the Python documentation

Don't search for solutions of the problems online (CHEATING) Writing functions in any problem gives a bonus!

Use ideone.com 

Choose language "Python 3"

https://www.ideone.com/ (https://www.ideone.com/)

Or Colab on Google Drive

This tutorial shows how to add Colab to your drive and access files stored on your drive e.g., data or text files.

Ignore the part about "change runtime to GPU"

https://www.mlfairy.com/blog/2020/01/15/google-colab-getting-started/ (https://www.mlfairy.com/blog/2020/01/15/google- colab-getting-started/)

 

Q1.1 Write a program that checks if a number is positive, or negative, or zero.

Input: x=1 Output: positive Input: x=-4 Output: negative Input: x=0 Output: zero

 

Q1.2 Write a program that checks if a number is even or odd.

Input: x=1 Output: odd Input: x=-4 Output: even Input: x=0 Output: even

 

Q1.3 Write a program that checks if a number is positive, or negative, or zero. Also, if the number is even or odd.

Hint: define separate functions to check even/odd and positive/negative/zero

Input: x=1

Output: positive odd Input: x=-4

Output: negative even Input: x=0

Output: zero even

 

Q2.1 Write a program that finds the largest number of 3 given numbers.

Input: x=1; y=2; z=3 Output: 3

Input: x=5; y=10; z=2 Output: 10

 

Q2.2 Write a program that finds the smallest number of 3 given numbers.

Input: x=1; y=2; z=3 Output: 1

Input: x=5; y=10; z=2 Output: 2

 

Q2.3: Write a program that finds the largest and smallest number of 3 given numbers

Hint: define two separate variables: one for the largest and one for the smallest

 

Input: x=1; y=2; z=3

Output: largest 3, smallest 1 Input: x=5; y=10; z=2

Output: largest 10, smallest 2

 

Q3 Write a program that calculates the sum of squares (power 2) of numbers in a given range of numbers

For example: start=1; end=3 then sum 1 2 + 2 2 + 3 ** 2 = 1 + 4 + 9 = 14 Hint: remember to define a total sum variable

Bonus: search for "list comprehension" and use it to solve this problem with "range" and "sum" functions

Input: start=1; end=3 Output 14

Input: start=5; end=10 Output: 355

 

Q4.1 Write a program that generates 10 random numbers between 1 and 100

Hint: use "random.choice" and a loop

Output: [65, 38, 57, 20, 19, 24, 13, 41, 17, 15]

 

Q4.2 Write a program to generate 10 random even numbers between 1 and 100

Hint: use "random.choice"

Bonus: search how to use "random.sample" instead

Output: [44, 4, 70, 8, 88, 18, 30, 12, 60, 68]

 

Q5.1 Write a program to check if a list of numbers is in increasing order

Input: [1,2,3] Output: yes Input: [1,2,0,3]

Output: no

 

Q5.2 Write a program to check if a list of numbers is in decreasing order

Input: [3,2,1] Output: yes Input: [3,2,0,1]

Output: no

 

Q5.3 Write a program to check if a list of numbers is increasing, or decreasing, or neither.

Input: [1,2,3] Output: increasing Input: [3,2,1] Output: decreasing Input: [1,0,2] Output: neither

 

Q6 Write a program to check a list is empty or not

Hint: use "len" function

Input: [] Output: yes Input: [1,2] Output: no

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme