- Go to HTML View of blog post's editor.
- Paste the below lines inside HTML editor & replace the Your Actual Code with the desired code.
Search This Blog
How to show code on blogger / blogspot with a copy snippet button
Turtle Race : Python Project for Beginners
1. 5 turtles of unique colors compete against each other.
2. User gets a chance to guess which color turtle will win the race.
3. If the user's guess is right it says you've won otherwise you lose!
Few screenshots of the game:
Doodle it: Imagine, Draw, Erase and Repeat - Python Project for Beginners
In order to create this game first step is to know a way of being able to listen to things the user does, like when a user taps a specific key on the keyboard. And the code that allows us to do this are called Event Listeners.
Go to python documentation > listen method()
It has a whole bunch of section-on-screen events, including listening to key presses or listening to a click or other things that you can listen to. So the important thing is this listen method.
Full key list for python's turtle- screen events ( Event Listeners )
Screen events
turtle.
onkey
(fun=function_name, key='Backspace')turtle.
onkeyrelease
(fun=function_name, key='Left')fun – a function with no arguments or
None
key – a string: key (e.g. “a”) or key-symbol (e.g. “space”)
.keysym | .keycode | .keysym_num | Key |
---|
Alt_L | 64 | 65513 | The left-hand alt key |
Alt_R | 113 | 65514 | The right-hand alt key |
BackSpace | 22 | 65288 | backspace |
Caps_Lock | 66 | 65549 | CapsLock |
Control_L | 37 | 65507 | The left-hand control key |
Control_R | 109 | 65508 | The right-hand control key |
Delete | 107 | 65535 | Delete |
Down | 104 | 65364 | ↓ |
End | 103 | 65367 | end |
Escape | 9 | 65307 | esc |
F1 | 67 | 65470 | Function key F1 |
F2 | 68 | 65471 | Function key F2 |
Fi | 66+i | 65469+i | Function key Fi |
F12 | 96 | 65481 | Function key F12 |
Home | 97 | 65360 | home |
Insert | 106 | 65379 | insert ( ins) |
Left | 100 | 65361 | ← |
K0 | 90 | 65438 | 0 on the keypad |
1 | 87 | 65436 | 1 on the keypad |
2 | 88 | 65433 | 2 on the keypad |
3 | 89 | 65435 | 3 on the keypad |
4 | 83 | 65430 | 4 on the keypad |
5 | 84 | 65437 | 5 on the keypad |
6 | 85 | 65432 | 6 on the keypad |
7 | 79 | 65429 | 7 on the keypad |
8 | 80 | 65431 | 8 on the keypad |
9 | 81 | 65434 | 9 on the keypad |
+ | 86 | 65451 | + on the keypad |
. | 91 | 65439 | Decimal (. ) on the keypad |
Delete | 91 | 65439 | delete on the keypad |
/ | 112 | 65455 | / on the keypad |
Down | 88 | 65433 | ↓ on the keypad |
Enter | 108 | 65421 | enter on the keypad |
Home | 79 | 65429 | home on the keypad |
Left | 83 | 65430 | ← on the keypad |
* | 63 | 65450 | × on the keypad |
Prior | 81 | 65434 | PageUp on the keypad |
Right | 85 | 65432 | → on the keypad |
- | 82 | 65453 | - on the keypad |
Up | 80 | 65431 | ↑ on the keypad |
Next | 105 | 65366 | PageDown / pg dn |
Num_Lock | 77 | 65407 | NumLock |
Pause | 110 | 65299 | pause |
Print | 111 | 65377 | PrintScrn / prt sc |
Right | 102 | 65363 | → |
Scroll_Lock | 78 | 65300 | ScrollLock |
Shift_L | 50 | 65505 | The left-hand shift key |
Shift_R | 62 | 65506 | The right-hand shift key |
Tab | 23 | 65289 | The tab key |
Turtle's random walk - Python
How to let turtle making random movements in the East, North, South, or West in Python?
Rules for Python's Turtle:
1. Each time it moves in a random direction.
2. In each direction it chooses a random color
3. Each time line's thickness increases
4. Each time it covers the same distance
5. Walks on screen in its fastest mode
Solution:
Draw different shapes like triangle, square, pentagon, hexagon in python using turtle
How to draw a triangle, square, pentagon, hexagon, heptagon, octagon, nonagon, and decagon in one go using turtle class of python?
Code:
How to draw a dashed line in python?
It's part of core python libraries so, turtle comes by default with basic python. Just need to import and use.
After importing the turtle, we use the penup and pendown to draw a dashed line. Penup simply means not drawing & Pendown is drawing a line. Like in the code below turtle module's penup & pendown are used to draw a black dashed line.
Solution to Techgig 30 Days Python Challenge - Day 7 (HARD)
Count special numbers between boundaries (100 Marks)
Input Format
For this challenge, you need to take two integers on separate lines. These numbers defines the range.Constraints
1 < = ( a , b ) < = 100000Output Format
output will be the single number which tells how many prime numbers are there between given range.Sample TestCase 1
Explanation
There are 8 prime numbers which lies in the given range.
They are 2, 3, 5, 7, 11, 13, 17, 19
- Time Limit(X):
- 1.00 sec(s) for each input.
- Memory Limit:
- 512 MB
- Source Limit:
- 100 KB
- Allowed Languages:
- C, C++, C++11, C++14, C#, Java, Java 8, PHP, PHP 7, Python, Python 3, Perl, Ruby, Node Js, Scala, Clojure, Haskell, Lua, Erlang, Swift, VBnet, Js, Objc, Pascal, Go, F#, D, Groovy, Tcl, Ocaml, Smalltalk, Cobol, Racket, Bash, GNU Octave, Rust, Common LISP, R, Julia, Fortran, Ada, Prolog, Icon, Elixir, CoffeeScript, Brainfuck, Pypy, Lolcode, Nim, Picolisp, Pike
SOLUTION DAY-07: (100 Marks)
Solution to TCS Pan India Hiring Drive - Python [ Coding Round ]
Question:
Minimum Absolute Difference (100 Marks)
You have an array of size N. Calculate the sum of minimum absolute differences for all the elements of the given array.
Note: N will always be an even number.
Input Format
The first line contains a single integer N, the size of the array.
The second line contains N integers, the elements of the array.
Constraints
2 <= N <= 103
0 <= Ai <= 103
Output Format
Print the sum of minimum absolute differences.
Note: There is a new line at the end of the output.
Sample TestCase 1
Input
4
5 10 10 15
Output
10
Explanation
Minimum absolute difference for element 1 = 5
Minimum absolute difference for element 2 and 3 = 0
Minimum absolute difference for element 4 = 5
Sum of minimum absolute differences = 5 + 0 + 0 + 5 = 10
Sample TestCase 2
Input
6
1 3 3 7 4 7
Output
3
Solution:
Object Oriented Quiz Project - Python
QUIZ GAME RULES:
- In this quiz project, there is a total of 12 questions. And on the basis of the user's typed answer, the score will be awarded to them. Each question is of 1 mark. The answer can be either True or False.
- The program is using an object-oriented approach.
- When a user types the wrong or right answer, share these remarks with them:
- If wrong: print("That's wrong")
- If right: print("You got it right!")
- You've completed the quiz.
- Your final score was: final_score/question_number
# TODO 1: the list to store the question data
# TODO 2: import all the dependent classes, methods
# TODO 3: Get the data from the dat.py and allocate the memory to the data(question, answer)
# TODO 4: Append each allocated data to the list
# TODO 5: Pass the question list to the quiz brain for actions
# TODO 6: Continue asking questions until the end of the question list
# TODO 7: Display the final score and quiz is ended remark
Code- main.py :
# TODO 1: asking the questions
# TODO 2: checking if the answer was correct
# TODO 3: checking if we're at the end of the quiz
Code- quiz_brain.py :
-
Hashing to Solutions: Two Sum Longest Substring Without Repeating Characters Longest Palindromic Substring Container With Mos...
-
Hey! Here, am on Day 02 of Angela's course. Though my heading says Day 04 which is actually done to stay in order of all the python le...
-
Exploring Data Types TechGig The question asked to check out the data type of the user input. It was quite tricky as python by default conve...