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.
In Python write a loop that tests whether two lists contain the same integers in the...
In Python write a loop that tests whether two lists contain the same integers in the same order: listA = [1, 2, 3, 4] listB = [1, 2, 3, 4] equal = True for ______ in ______:    if _______ != ________ :       _______ = ________ if equal:    print(_______) else:    print(_______)
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT