Question

In: Computer Science

Python Please debug each python block. Do not change the algorithm. You can add statements or...

Python

Please debug each python block. Do not change the algorithm. You can add statements or you can modify existing python statements.

#2) The below code prints all numbers from 5 to 20. Modify the below while loop to print odd numbers from 5 to 21,
# including 21. Correct syntax errors as well.

i = 5
while(i<21):
print(i)
i = i+1

Solutions

Expert Solution

1 PYTHON CODE TO PRINT ALL NUMBERS FROM 5 TO 20 ===>

# CODE TO PRINT INTEGERS FROM 5 TO 20
i = 5 # initialize value i = 5
while(i<21): # run loop until i = 21
print(i) # print all i
i = i+1 # increment i

CODE SCREENSHOT ====>

OUTPUT SCREENSHOT ===>

2 . MODIFIED CODE ( INCLUDE 21 ) ====>

# CODE TO PRINT INTEGERS FROM 5 TO 20
i = 5 # initialize value i = 5
while(i<=21): # run loop until i = 21
print(i) # print all i
i = i+1 # increment i

CODE SCREENSHOT ====>

OUTPUT SCREENSHOT ====>


Related Solutions

2. Add a title comment block to the top of the new Python file using the...
2. Add a title comment block to the top of the new Python file using the following form # A brief description of the project 3. Ask user - to enter the charge for food 4. Ask user - to enter theTip for server ( remember this is a percentage , the input therefore should be decimal. For example, for a 15% tip, 0.15 should be entered) 5. Ask user - to enter the Tax amount ( this is a...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
Can you please solve these questions/ statements using python? I started with "importing" the file. I...
Can you please solve these questions/ statements using python? I started with "importing" the file. I only need question one to be answered not two-four. Can use whatever data frame of choice, I just need a sample code for each line. Thank you #1. #Fit a linear regression model on data: USA_housing.csv to predict the Price of the house. import pandas as pd housing_df = pd.read_csv("USA_Housing.csv") #Income: Avg. area income #Age: Avg age of the houses #Bedrooms: Avg No of...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Using Python In this assignment we will try to add tuples, lists, if statements and strings...
Using Python In this assignment we will try to add tuples, lists, if statements and strings to our program. For example, you can ask for a user for a couple items, their name and age – and depending on their age, print out a predefined list. You could ask for some string input and decide to do something with the output. You could ask for three items, 1) age, 2) are you a male or female and 3) are your...
This is a radix sort algorithm. please add the date type and the instruction given inside...
This is a radix sort algorithm. please add the date type and the instruction given inside the code to make it completely work. please do not change the code just follow the instruction. #include <iostream> using namespace std; // Returns the length, in number of digits, of value int RadixGetLength(int value) { if (value == 0) return 1; int digits = 0; while (value != 0) { digits = digits + 1; value = value / 10; } return digits;...
Please using python to do the following code: You roll two six-sided dice, each with faces...
Please using python to do the following code: You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated. • If the sum is 7 or 11 on the first roll, you win. • If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins). •...
You will utilize a large dataset to create a predictive analytics algorithm in Python. For this...
You will utilize a large dataset to create a predictive analytics algorithm in Python. For this assignment, complete the following: Utilize one of the following Web sites to identify a dataset to use, preferably over 500K from Google databases, kaggle, or the .gov data website Utilize a machine learning algorithm to create a prediction. K-nearest neighbors is recommended as an introductory algorithm. Your algorithm should read in the dataset, segmenting the data with 70% used for training and 30% used...
asap please python Using block diagram, design the architectural layout of the simplified model of a...
asap please python Using block diagram, design the architectural layout of the simplified model of a symmetric Cryptosystem. Implement a cryptosystem columnar transposition technique with a 4 x 4 matrix arrangement. Test your code with ‘cryptography’ as the plaintext.
Can you please write this in python and comment as well so I can understand what...
Can you please write this in python and comment as well so I can understand what yo are doing. Thank you. 1)Loop through list A, at each iteration, show the square root result of that element. Add proper text to your print function. A = [-4, 1, -16, 36, -49, 64, -128] 2)Create a counter variable, name it i and initialize it to 0. Using a for loop, count how many numbers are divisible by 3 in range of 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT