This content originally appeared on DEV Community and was authored by dev.to staff
Greetings, Jedi Padawans, fellow coders, and esteemed Jedi Knights.
In the Star Wars universe, Jedi Knights are skilled in the use of the Force, a mystical energy that they can manipulate to achieve various abilities. In this coding challenge, we'll be simulating Jedi training by creating a program that generates a sequence of numbers and applies various transformations to them using...the power of code!
Instructions:
Write a program that generates a sequence of 10 random numbers between 1 and 10.
Use the Force (code) to apply the following transformations to the sequence:
- Multiply every even number by 2
- Add 5 to every odd number
- Replace any number greater than 10 with 1
- Print the final sequence to the console.
Hints:
- You can use the rand method in Ruby or the random module in Python to generate random numbers.
- You can use an if statement to check whether a number is even or odd.
- You can use a for loop to iterate over the sequence and apply the transformations.
The challenge begins. May the fourth be with you!
This content originally appeared on DEV Community and was authored by dev.to staff
dev.to staff | Sciencx (2023-05-04T15:00:00+00:00) Jedi Training Challenge. Retrieved from https://www.scien.cx/2023/05/04/jedi-training-challenge/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.