Question

In: Computer Science

Python Practice Sample: Generate lists containing the numbers between 1 and 50 as follows:  same...

Python Practice Sample:

Generate lists containing the numbers between 1 and 50 as follows:

 same is a list of all the two-digit numbers whose digits are the same (11, 22, etc.)

 addsto6 is a list of all numbers the sum of whose digits is 6

 rest contains the rest of the numbers.

A number can appear only in one of the lists; with same having higher priority. (So for example, 33 would appear in the same, but NOT the addsto6 list).

Same = [11, 22, 33, 44]

AddsTo6 = [6, 15, 24, 42]

Rest = [1, 2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 23, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 43, 45, 46, 47, 48, 49, 50]

Solutions

Expert Solution

Code and outptut

Code for copying

Same=[]
AddsTo6=[]
Rest=[]
for i in range(10,51):
j=str(i)
if j[0]==j[1]:
Same.append(i)
for i in range(1,51):
total=0
j=str(i)
if i<10:
for n in j:
total+=int(n)
if i>=10:
if j[0]!=j[1]:
for n in j:
total+=int(n)
  
if total==6:
AddsTo6.append(i)
for i in range(1,51):
if i not in (Same + AddsTo6):
Rest.append(i)
print("Same={}".format(Same))
print("AddsTo6={}".format(AddsTo6))
print("Rest={}".format(Rest))
  
  
  

Code snippet

Same=[]
AddsTo6=[]
Rest=[]
for i in range(10,51):
    j=str(i)
    if j[0]==j[1]:
        Same.append(i) 
for i in range(1,51):
    total=0
    j=str(i)
    if i<10:
        for n in j:
            total+=int(n)
    if i>=10:
        if j[0]!=j[1]:
            for n in j:
                total+=int(n)
            
    if total==6:
        AddsTo6.append(i)
for i in range(1,51):
    if i not in (Same + AddsTo6):
        Rest.append(i)
print("Same={}".format(Same))
print("AddsTo6={}".format(AddsTo6))
print("Rest={}".format(Rest))
        
        
    

Related Solutions

Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
Use Python to plot poisson process for time interval [0,50] that generate 50 random numbers.
Use Python to plot poisson process for time interval [0,50] that generate 50 random numbers.
its a c++ programme. In your program, you will randomly generate integer numbers between -50 and...
its a c++ programme. In your program, you will randomly generate integer numbers between -50 and +50 (including -50 and +50). You will repeat this process 1000 times. While generating these numbers, you need to count the numbers based on their signs separately, as positive and negative. For instance, if your program generate +25 15 times, and -25 19 times. Then this should be reported as, Num PosFre NegFre 25 15 19 For this problem, you need to use array...
in PYTHON given a specific text file containing a list of numbers on each line (numbers...
in PYTHON given a specific text file containing a list of numbers on each line (numbers on each line are different) write results to a new file after the following tasks are performed: Get rid of each line of numbers that is not 8 characters long Get rid of lines that don't begin with (478, 932, 188, 642, 093)
Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion...
Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion #Create and assign the following list of numbers to a list data type and variable name: 99.9,88.7,89,90,100 #convert the list to a tuple and assign the tuple a different variable name #Ask the user for a grade and convert it to a float type (no prompt) and assign it to a new variable name #append the user entered grade to the list #update the...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.
1. Write a python function that receives two positive numbers and displays the prime numbers between...
1. Write a python function that receives two positive numbers and displays the prime numbers between them.Note: A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors other than 1 and itself. 2. Using either Whileor Foriteration loops, write a python code that prints the first Nnumbers in Fibonacci Sequence, where N is inputted by the user. Now, revise this code to instead print a) the Nthnumber in Fibonacci Sequence.b) the...
how to use subsetting in Python lists. Practice making subsets of the namelist. import matplotlib.pyplot as...
how to use subsetting in Python lists. Practice making subsets of the namelist. import matplotlib.pyplot as plot # set up your lists numlist = [8, 6, 5, 3] namelist = ['freshmen', 'sophomores', 'juniors', 'seniors'] colorlist = ['red', 'green', 'pink', 'yellow' ] explodelist = [0.1, 0.0, 0.0, 0.0] # make the pie chart plot.pie(numlist, labels=namelist, autopct='%.2f%%', colors=colorlist,         explode = explodelist, startangle = 90) plot.axis('equal') plot.savefig('piechart.png')
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT