Assume that the variables low and high have been declared and assigned integer v
ID: 3686688 • Letter: A
Question
Assume that the variables low and high have been declared and assigned integer values (and that the value of low is less than the value of high). Write some Python code that will print out all of the values from low through high (inclusive) that are evenly divisible by 3, and only those values. For example, if low is 5 and high is 21, your code should print out exactly 6, 9, 12, 15, 18, and 21.
An election is held to pick a new mayor. There are two candidates for office: Alice and Bob. The city contains 5 voting districts where people will be casting votes. Write a text-only Python program that takes as input the number of votes (as integers) that each candidate received in each voting district and calculates the total number of votes for each candidate. Use a loop. The program should print out the percentage of votes that each candidate received and the name of the winner.
24. Write some Python code that will calculate and print the sum of all the numbers from 1 to 1000 (inclusive), that are multiples of 3 or 5. Your program may use whatever data structures and variables you deem necessary (you dont need much of anything for this problem though), but be sure that you only print the answer, once.
Explanation / Answer
20)
if(i % 3 == 0 for i in range(low,high)):
print(i)
21)
def calculate(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10):
Alice_votes=v2+v4+v6+v8+v10
Bob_votes=v1+v3+v5+v7+v9
print '% of alice votes:'
print (Alice_votes/(Alice_votes+Bob_votes))*100
print '% of bob votes:'
print (Bob_votes/(Alice_votes+Bob_votes))*100
end
22)
n=1;
while n<1000:
if n%3 ==0 or n%5 ==0:
print n
n=n+1