×

Challenges

Challenge 2.2

# Display number of dots from right to left in one line

Challenge Level: Growing experience

## Requirement:

Write a program to display numbers 1, 2, 4, 8,... (all in one line) for a given number of cards as the input.

Hints
• Make variables:

• number_of_cards to store the number of cards to display entered by the end user as the input (e.g. 4).
• number_of_dots to store the number of dots.
• binary_cards which is a variable type string and stores what is going to be displayed on the screen as the output (e.g. "1, 2, 4, 8,").
• Use the addition operator to combine strings. You can use multiple to combine multiple strings. Remember to check if the spaces are correct between the items being joined!
• Use the input() function to get the user's input. You can place text inside the brackets of input if you'd like to display your question.
Programming Reminders
# Print a string directly
print("Hello World!")

# Print a variable
print(my_var)

#### Variables

# Set a variable as a string
fruit_name = "Apple"

# Set a variable as an integer
pieces_of_fruit = 7

# Set a variable from a calculation
cost_of_fruit = pieces_of_fruit * cost_per_item

# Add one to a value
pieces_of_fruit += 1

#### Conditionals

# Find out the discount on fruit
if pieces_of_fruit > 100:
print("Bulk discount applies")
elif pieces_of_fruit > 5:
print("Discount applies")
else:
print("No discount")

#### For loops

# Print numbers 0-9 - remember Python starts counting from 0
for num in range(10):
print(num)

#### While loops

# Print numbers 0-9 using a while loop and a variable
num = 0
while num < 10:
print(num)

# Increment the variable by one.
# It will prevent an infinite loop!
num += 1 

#### Lists

# Create a list of fruit
fruit = ["Apple", "Banana", "Orange", "Pear"]

#### Functions

# Create a function which prints a greeting
def greeting(name):
print("Hello " + name)

# Call the function
greeting("Spiderman")

Enter your code in the editor below

Your results will be displayed here

Input Expected output Received output Status
1
1,

Not yet run ?
4
1, 2, 4, 8,

Not yet run ?
8
1, 2, 4, 8, 16, 32, 64, 128,

Not yet run ?