[[TOC]]
There may be times when you want to have a result
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
fruits = ["banana", "apple", "orange", "kiwi"]
while(len(fruits) > 1):
fruits.pop()
print(fruits)
-
Say you have a list of numbers. Many of them are duplicate, create a script to eliminate the duplication. Your program behavior should exactly the same as below:
$ python3 duplicate.py Give me a list of numbers: [1,2,3,2,3,4,5,1] Okay!! Here you are: [1,2,3,4,5]
-
Generate a random number between 1 to 9. Ask the user to guess the number then answer whether it's too high, too low or the number is right.
-
Say there is a robot in a point of location (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with given steps. The trace of robot movement is shown as the following:
UP 5 DOWN 3 LEFT 3 RIGHT 2
The numbers after the direction are steps. Please write a program to compute the distance from the position after the movement and the original point. If the distance is a float, then just print the nearest integer. The output of your program should be:
Robot location is 2, 1 Distance is 2
Hint:
Distance is round of square of y power of 2 plus x power of 2 -
Say you are playing a game of
rock-paper-scissors
with the computer.
Remember rock beats scissors, paper beats rock, scissors beats paper and if it's the same then it's a draw.
If you quit the game, there will be a score printed between you versus the computer.
Please write a program for this game. -
Say you are going to write a code for a game to guess a word. The features are explained below:
1. When the game start, your program will ask for a character 2. User can guess for many times but only 5 times given for the wrong character guessed. More than 5, they are losing. 3. If they are giving a right character, let them know they are right. 4. If the user already guesses the character, don't penalize them, ask them to guess again. 5. If the user wins or loses, let them start a new game or quit.