diff --git a/.replit b/.replit new file mode 100644 index 0000000..5391a66 --- /dev/null +++ b/.replit @@ -0,0 +1,2 @@ +language = "python3" +run = "python bell_number.py" diff --git a/Day-2/README.md b/Day-2/README.md index 55cd2ca..6ebc7da 100644 --- a/Day-2/README.md +++ b/Day-2/README.md @@ -1,12 +1,12 @@ -##Silly Sentence Generator +## Silly Sentence Generator Our next project is a silly sentence generator that will randomly pick words from lists to generate a funny sentence. -Open the starter file: [silly sentence generator.py](silly sentence generator.py). Copy all the code into a new Python window. +Open the starter file: [silly sentence generator.py](silly%20sentence%20generator.py). Copy all the code into a new Python window. -###Let's look at the code: +### Let's look at the code: -####Lists +#### Lists Up until now, we've stored things in one variable at a time. A list is a way to collect multiple values in one variable. Let's make a list: @@ -21,7 +21,7 @@ We can look at specific items in the list with an *index*, and indexes start fro apples ``` -####Random +#### Random We can use the random module to create random numbers: @@ -32,7 +32,7 @@ random.randint(0,5) A module is something extra in Python that lets you go beyond what Python lets you do by default. -####The `random_word` Function +#### The `random_word` Function The `random_word` function picks a random index from 0 to the last item in the list. Then, it finds the word with that index, and hands it back: ```python @@ -46,26 +46,26 @@ def random_word(list_of_words): *Functions* in Python let you take a piece of code and use it over and over again. -#####Functions +##### Functions We can use the `def` keyword to define a function. Functions let you send something to the function, and the function sends you something back. You can re-use functions by sending them different data, and they'll send you different data back. In the statement `random_word(verb_list)`, `verb_list` is what we're sending to the function. The function doesn't care that it's the verb list, so we can give it any list of words. -###Add our own code! +### Add our own code! -####Create your own noun and adjective lists +#### Create your own noun and adjective lists Look at how the verb list was done. We can make our own lists of adjectives and nouns, and maybe add some more verbs for variety. -####Use the function to select random words from each list +#### Use the function to select random words from each list You will need 5 variables: `adjective1`, `noun1`, `verb`, `adjective2`, and `noun2`. Remember, we can re-use functions by passing them different information, and they'll send different information back. -####Print the result in a sentence. +#### Print the result in a sentence. Be sure to insert the word "the" in the right places. What sentences can you make? -####`random.choice` +#### `random.choice` We just wrote a function to pick a random word from a list of words. However, the `random` module already gives us a way to do this. We can use `random.choice` to write a new version of `random_word`: ```python @@ -75,10 +75,10 @@ def random_word2(list_of_words): We've just shortened a 4-line function to a 1-line function. When you have a 1-line function, you have to think, "Do I really need that function?" In this case, it's kind of OK, because we arrived at that 1-line function by a process of iteration. -####Making more silly sentences +#### Making more silly sentences Can you change the program to print 10 silly sentences instead of 1? Look back at [the notes from last week](../day-1) if you need to remember how loops work. -####Possible extensions +#### Possible extensions * Improve your word list. If you like Minecraft, for example, add some Minecraft terms! * Improve the sentences' grammar diff --git a/Extras/README.md b/Extras/README.md index 8f6eaa0..3fafb17 100644 --- a/Extras/README.md +++ b/Extras/README.md @@ -1,8 +1,8 @@ -#More Text-Based Programs To Try +# More Text-Based Programs To Try Days 1, 2, and 3 have focus on text-based games and programs. Here are some more fun text-based programs to try. -###Hailstone Pattern +### Hailstone Pattern The hailstone pattern is a cool number pattern that for any positive whole number, it will always end in one. It repeats the following steps until it gets to one: if the number is even, it will divide by two. If the number is odd, it will multiply by three and add one. @@ -42,24 +42,24 @@ What happens when you enter a really big number? How many steps does it take? Refer to the finished folder for a complete example. -###Tic-Tac-Toe +### Tic-Tac-Toe The San Francisco CoderDojo has done a really fun Tic-Tac-Toe Python project that you can go through. Head to https://github.com/CoderDojoSF/tic-tac-toe and follow the links for Lesson 1 and Lesson 2! -###Dragon Realm - Invent With Python +### Dragon Realm - Invent With Python [Invent With Python](http://inventwithpython.com/) is a free online Python book with some great projects. Chapter 6 (page 84) in the book shows how to create a text-adventure game called Dragon Realm. [Here is the online pdf version of the book](http://inventwithpython.com/IYOCGwP_book1.pdf). -###Invent With Python - Hangman +### Invent With Python - Hangman [Invent With Python](http://inventwithpython.com/) is a free online Python book with some great projects. Chapter 9 (page 132) in the book shows how to create the letter and word guessing game Hangman. [Here is the online pdf version of the book](http://inventwithpython.com/IYOCGwP_book1.pdf). -###Bagels - Invent With Python +### Bagels - Invent With Python [Invent With Python](http://inventwithpython.com/) is a free online Python book with some great projects. @@ -73,9 +73,9 @@ Chapter 11 (page 217) in the book shows how to create a number guessing game cal -##More Graphics Programs to Try +## More Graphics Programs to Try -###Snake +### Snake Snake is a game where you control an always moving character using the keys. The goal is to hit the target without hitting a wall. If you get the target, your character starts moving faster and the target appears somewhere else. The game ends when you hit the wall. @@ -83,7 +83,7 @@ Here is an example of the game created in Scratch: http://scratch.mit.edu/projec Refer to the finished folder for a complete example. -###Adding Complexity - Functions that Set Variables +### Adding Complexity - Functions that Set Variables If you want to make more complex games, there are some additional concepts that you can put to use. The first is using functions (which you have created before) to change variables. @@ -110,7 +110,7 @@ def reset_ball(side): Functions are a powerful way to start creating more impressive games. -###Adding Complexity - Classes and Sprites in Pygame +### Adding Complexity - Classes and Sprites in Pygame For the 6 day track we didn't cover using sprites in Pygame because it involves a new concept: classes. A class can be thought of as a blue-print that you can use to create many copies of something. Each copy can have their own set of variables (called properties). In pong there were already a lot of variables to keep track of, what if the game had many more objects in it! @@ -118,7 +118,7 @@ Take a look at [catch the good ones.py](Finished/catch the good ones.py) for an There are many sources to learn more about Pygame sprites and creating Python classes. If you are learning on your own, check out a book like [Hello World! Computer Programming for Kids and Other Beginners](http://www.amazon.com/Hello-World-Computer-Programming-Beginners/dp/1933988495). -###Breakout +### Breakout Take a look at [breakout.py](Finished/breakout.py) for another game that uses a class. (You must also download the brick.png file in the [Finished](Finished/) folder.) diff --git a/README.md b/README.md index f63c13e..391dee2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Run on Repl.it](https://repl.it/badge/github/CoderDojoSV/beginner-python)](https://repl.it/github/CoderDojoSV/beginner-python) + #Introduction to Python *Learn Python to make text and 2-D games with a typed programming language!* diff --git a/bell_number.py b/bell_number.py new file mode 100644 index 0000000..b14fc15 --- /dev/null +++ b/bell_number.py @@ -0,0 +1,22 @@ +#Python program to print bell number +#Bell Number:-Let S(n, k) be total number of partitions of n elements into k sets. The value of n’th Bell Number is sum of S(n, k) for k = 1 to n. Value of S(n, k) can be defined recursively as, S(n+1, k) = k*S(n, k) + S(n, k-1) +A sample Bell triangle is as follows: +1 +1 3 +3 8 13 +13 23 33 43 +#The code to print the bell triangle is as follows- +#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +n=int(input("enter the number of bell")) #taking value from the user +bell=0 #initialising bell to 'zero' +k=0 #initialising k to 'zero' +for i in range(0,n): #loop for changing rows from 0 to n + for j in range(0,i+1): #printing columns + if j==0 and i>0: #repeating the last number of previous row in new row + print(bell,'',end='') #printing first number of each line + else: + k=(i**2)+1+bell #to generate other numbers of line + print(k,'',end='') #printing other number in lines + bell=k #updating value of bell + print('\n') #for moving into next lines +print("last number of bell is",bell)