Question

In: Computer Science

Python Language: Similar to Project 3, write a program that loops a number from 1 to...

Python Language:

Similar to Project 3, write a program that loops a number from 1 to 10 thousand and keeps updating a count variable according to these rules:

if the number is divisible by n1, increase count by 1
if the number is divisible by n2, increase count by 2
if the number is divisible by n3, increase count by 3
if none of the above conditions match for the number, increase count by the number.

Before the loop begins, count should be set to 0. Once the loop is complete, print the value of count.

n1, n2, and n3 should be set as follows:

n1 = 11

n2 = 64

n3 = 107

Just like the previous projects, the value of a=1, the value of b=2, ..., the value of z=26.

The program must produce one numeric output (it should be the value of count).

Solutions

Expert Solution

Python code:

#setting count as 0
count=0
#setting n1 as 11
n1=11
#setting n2 as 64
n2=64
#setting n3 as 107
n3=107
#looping from 1 to 10000
for i in range(1,10001):
#checking if number is divisible by n1
if(i%n1==0):
#incrementing count by 1
count+=1
#checking if number is divisible by n2
elif(i%n2==0):
#incrementing count by 2
count+=2
#checking if number is divisible by n3
elif(i%n3==0):
#incrementing count by 3
count+=3
else:
#incrementing count by number
count+=i
#printing count
print(count)


Screenshot:


Output:


Related Solutions

CODE MUST BE IN C++ write a program that loops a number from 1 to 10...
CODE MUST BE IN C++ write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above...
Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0. 2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A. B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark] 3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your...
c# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
Python Write a program that loops, prompting the user for their full name, their exam result...
Python Write a program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules: First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long. Exam result (an integer between 1 and 100 inclusive) The file should record...
Write a python program that loops, prompting the user for their full name, their exam result...
Write a python program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules: First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long. Exam result (an integer between 1 and 100 inclusive) The file should record...
23.2 PROJECT 2 : Data Visualization using LOOPS (python) This program will display a set of...
23.2 PROJECT 2 : Data Visualization using LOOPS (python) This program will display a set of authors and the number of novels written by each author in both a table and a histogram. You will ask the user for all of the information. Using what you learned about incremental development, use the following approach to create your program: Prompt the user for the information about the table. First, ask for the title of this data set by prompting the user...
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT