From 5c3e1c2ed86b57838d16151e4d9c305eae565084 Mon Sep 17 00:00:00 2001 From: Ananyagra24 <155280507+Ananyagra24@users.noreply.github.com> Date: Sun, 12 May 2024 21:49:55 +0530 Subject: [PATCH 01/17] Create History --- contrib/History | 1 + 1 file changed, 1 insertion(+) create mode 100644 contrib/History diff --git a/contrib/History b/contrib/History new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/contrib/History @@ -0,0 +1 @@ + From b8e682d2fd427f8c76bde3bc30207cad327aec5d Mon Sep 17 00:00:00 2001 From: Ananyagra24 <155280507+Ananyagra24@users.noreply.github.com> Date: Mon, 13 May 2024 08:40:22 +0530 Subject: [PATCH 02/17] Delete contrib/History --- contrib/History | 1 - 1 file changed, 1 deletion(-) delete mode 100644 contrib/History diff --git a/contrib/History b/contrib/History deleted file mode 100644 index 8b13789..0000000 --- a/contrib/History +++ /dev/null @@ -1 +0,0 @@ - From 83809066303a7f962f2063d1613bad26f9776c1d Mon Sep 17 00:00:00 2001 From: Ananyagra24 <155280507+Ananyagra24@users.noreply.github.com> Date: Mon, 13 May 2024 21:10:18 +0530 Subject: [PATCH 03/17] Create dice_roller.md --- contrib/mini-projects/dice_roller.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 contrib/mini-projects/dice_roller.md diff --git a/contrib/mini-projects/dice_roller.md b/contrib/mini-projects/dice_roller.md new file mode 100644 index 0000000..c083934 --- /dev/null +++ b/contrib/mini-projects/dice_roller.md @@ -0,0 +1,19 @@ +``` +import random +def dice(): + dice_no = random.choice([1,2,3,4,5,6]) + return "You got " + str(dice_no) +def roll_dice(): + print("Hey Guys, you will now roll a single dice using Python!") + while True: + start=input("Type \'k\' to roll the dice: ").lower() + if start != 'k': + print("Invalid input. Please try again.") + continue + print(dice()) + roll_again = input("Do you want to reroll? (Yes/No): ").lower() + if roll_again != 'yes': + break + print("Thanks for rolling the dice.") +roll_dice() +``` From f8a67cf65dc3d70cf0a81a0cebd55770f0ffc728 Mon Sep 17 00:00:00 2001 From: Ananyagra24 <155280507+Ananyagra24@users.noreply.github.com> Date: Mon, 13 May 2024 21:11:01 +0530 Subject: [PATCH 04/17] Update index.md --- contrib/mini-projects/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mini-projects/index.md b/contrib/mini-projects/index.md index 82596a2..f60b286 100644 --- a/contrib/mini-projects/index.md +++ b/contrib/mini-projects/index.md @@ -1,3 +1,3 @@ # List of sections -- [Section title](filename.md) +- [Dice Roller](dice_roller.md) From ea32f2bd8ce5c16960c66e72b6e886d9b260f51d Mon Sep 17 00:00:00 2001 From: Hema Sree Date: Wed, 15 May 2024 17:49:44 +0530 Subject: [PATCH 05/17] Added intro to numpy --- contrib/numpy/Introduction.md | 36 +++++++++++++++++++++++++++++++++++ contrib/numpy/index.md | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 contrib/numpy/Introduction.md diff --git a/contrib/numpy/Introduction.md b/contrib/numpy/Introduction.md new file mode 100644 index 0000000..59a1938 --- /dev/null +++ b/contrib/numpy/Introduction.md @@ -0,0 +1,36 @@ +# Introduction + +## What is Numpy? + +NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. It is the fundamental package for scientific computing with Python. It is open-source software. + +## Features of NumPy + +NumPy has various features including these important ones: + +1. A powerful N-dimensional array object +2. Sophisticated (broadcasting) functions +3. Tools for integrating C/C++ and Fortran code +4. Useful linear algebra, Fourier transform, and random number capabilities + +## Install Numpy + +Before installing Numpy, ensure you have Python installed on your system. You can download and install Python from the [official Python website](https://www.python.org/). + +Numpy can be installed via the following pip command: + +```bash +pip install numpy + +``` + +# How to import NumPy + +To access NumPy and its functions import it in your Python code like this: + +```bash +import numpy as np + +``` + +We shorten the imported name to np for better readability of code using NumPy. This is a widely adopted convention that makes your code more readable for everyone working on it. We recommend to always use import numpy as np. diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index 82596a2..c6bf23c 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,3 +1,3 @@ # List of sections -- [Section title](filename.md) +- [Introduction](Introduction.md) From 59e79c7627db41589dc554e1440d0ee5aacf3c9c Mon Sep 17 00:00:00 2001 From: Hema Sree Date: Wed, 15 May 2024 17:57:30 +0530 Subject: [PATCH 06/17] Added numpy intro --- contrib/numpy/Introduction.md | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/contrib/numpy/Introduction.md b/contrib/numpy/Introduction.md index 59a1938..c437c48 100644 --- a/contrib/numpy/Introduction.md +++ b/contrib/numpy/Introduction.md @@ -1,36 +1,30 @@ # Introduction -## What is Numpy? +## What is NumPy? -NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. It is the fundamental package for scientific computing with Python. It is open-source software. +NumPy is a powerful array-processing library in Python, essential for scientific computing. It provides efficient data structures and tools for working with multidimensional arrays. -## Features of NumPy +## Key Features -NumPy has various features including these important ones: +1. **Efficient Arrays:** NumPy offers high-performance N-dimensional array objects for swift data manipulation. +2. **Broadcasting:** Advanced broadcasting enables seamless element-wise operations on arrays of varying shapes. +3. **Interoperability:** NumPy seamlessly integrates with C, C++, and Fortran, enhancing performance and versatility. +4. **Mathematical Tools:** Comprehensive support for linear algebra, Fourier transforms, and random number generation. -1. A powerful N-dimensional array object -2. Sophisticated (broadcasting) functions -3. Tools for integrating C/C++ and Fortran code -4. Useful linear algebra, Fourier transform, and random number capabilities +## Installation -## Install Numpy - -Before installing Numpy, ensure you have Python installed on your system. You can download and install Python from the [official Python website](https://www.python.org/). - -Numpy can be installed via the following pip command: +Ensure Python is installed in your system. If not you can install it from here([official Python website](https://www.python.org/)),then install NumPy via: ```bash pip install numpy - ``` -# How to import NumPy +# Importing NumPy -To access NumPy and its functions import it in your Python code like this: +To access NumPy functions, import it with the alias `np`: -```bash +```python import numpy as np - ``` -We shorten the imported name to np for better readability of code using NumPy. This is a widely adopted convention that makes your code more readable for everyone working on it. We recommend to always use import numpy as np. +Using `np` as an alias enhances code readability and is a widely adopted convention. From 9f482ac8181b47e80c5469025ab067bab96ae54a Mon Sep 17 00:00:00 2001 From: Hema Sree Date: Wed, 15 May 2024 17:58:33 +0530 Subject: [PATCH 07/17] intro numpy --- contrib/numpy/Introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/Introduction.md b/contrib/numpy/Introduction.md index c437c48..c0f5f52 100644 --- a/contrib/numpy/Introduction.md +++ b/contrib/numpy/Introduction.md @@ -19,7 +19,7 @@ Ensure Python is installed in your system. If not you can install it from here([ pip install numpy ``` -# Importing NumPy +## Importing NumPy To access NumPy functions, import it with the alias `np`: From 989278ebe3ac868d63f6f66b9461474fb2f8679e Mon Sep 17 00:00:00 2001 From: Hema Sree Date: Thu, 16 May 2024 13:08:37 +0530 Subject: [PATCH 08/17] change file name --- contrib/numpy/Introduction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/Introduction.md b/contrib/numpy/Introduction.md index c0f5f52..eb3af67 100644 --- a/contrib/numpy/Introduction.md +++ b/contrib/numpy/Introduction.md @@ -21,7 +21,7 @@ pip install numpy ## Importing NumPy -To access NumPy functions, import it with the alias `np`: +To access NumPy functions, import it with the alias `np`. ```python import numpy as np From 7ae451cc067a73adc6068b18ddb461cea84942c6 Mon Sep 17 00:00:00 2001 From: Hema Sree Date: Thu, 16 May 2024 13:12:41 +0530 Subject: [PATCH 09/17] change file name --- contrib/numpy/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/numpy/index.md b/contrib/numpy/index.md index c6bf23c..5d3f63b 100644 --- a/contrib/numpy/index.md +++ b/contrib/numpy/index.md @@ -1,3 +1,3 @@ # List of sections -- [Introduction](Introduction.md) +- [Introduction](introduction.md) From 9bb50dcf528efb9cd1dbbd8970e5a52130c86482 Mon Sep 17 00:00:00 2001 From: HEMA SREE VEMULAMADA <109607812+Hemav009@users.noreply.github.com> Date: Thu, 16 May 2024 13:14:26 +0530 Subject: [PATCH 10/17] Rename Introduction.md to introduction.md --- contrib/numpy/{Introduction.md => introduction.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/numpy/{Introduction.md => introduction.md} (100%) diff --git a/contrib/numpy/Introduction.md b/contrib/numpy/introduction.md similarity index 100% rename from contrib/numpy/Introduction.md rename to contrib/numpy/introduction.md From 4be728eb4764637fa8072aeebcaa9965e619d578 Mon Sep 17 00:00:00 2001 From: Ananyagra24 <155280507+Ananyagra24@users.noreply.github.com> Date: Sun, 19 May 2024 09:44:37 +0530 Subject: [PATCH 11/17] Update dice_roller.md --- contrib/mini-projects/dice_roller.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/mini-projects/dice_roller.md b/contrib/mini-projects/dice_roller.md index c083934..6e1b793 100644 --- a/contrib/mini-projects/dice_roller.md +++ b/contrib/mini-projects/dice_roller.md @@ -1,8 +1,15 @@ +Dice Roller +
+The aim of this project is to replicate a dice and generate a random number from the numbers 1 to 6.

+For this first we will import the random library which will help make random choices. ``` import random def dice(): dice_no = random.choice([1,2,3,4,5,6]) return "You got " + str(dice_no) +``` +The above snippet of code defines a function called "dice( )" which makes the random choice and returns the number that is generated. +``` def roll_dice(): print("Hey Guys, you will now roll a single dice using Python!") while True: @@ -17,3 +24,6 @@ def roll_dice(): print("Thanks for rolling the dice.") roll_dice() ``` +The above code defines a function called "roll_dice( )" which interacts with the user.
+It prompts the user to give an input and if the input is k,the code proceeds further to generate a random number or gives the message of invalid input and asks the user to try again.
+After the dice has been rolled once, the function asks the user whether they want a reroll in the form of a yes or no question.The dice is rolled again if the user gives 'yes' as an answer and exits the code if the user replies with anything other than yes. From 4ee5b32b8e217eac48799391a2f8182ac2abae35 Mon Sep 17 00:00:00 2001 From: Pradnya <116059908+PradnyaGaitonde@users.noreply.github.com> Date: Tue, 21 May 2024 21:51:48 +0530 Subject: [PATCH 12/17] Create dates_and_times.md Added content for Working with dates & times in python --- contrib/advanced-python/dates_and_times.md | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 contrib/advanced-python/dates_and_times.md diff --git a/contrib/advanced-python/dates_and_times.md b/contrib/advanced-python/dates_and_times.md new file mode 100644 index 0000000..f599e26 --- /dev/null +++ b/contrib/advanced-python/dates_and_times.md @@ -0,0 +1,129 @@ +## Working with Dates and Times in Python +Handling dates and times is an essential aspect of many programming tasks. +Python provides robust modules to work with dates and times, making it easier to perform operations like formatting, parsing, and arithmetic. +This guide provides an overview of these modules and their key functionalities. + +## 1. 'datetime' Module +The datetime module supplies classes for manipulating dates and times. The main classes in the datetime module are: + +* date: Represents a date (year, month, day). +* time: Represents a time (hour, minute, second, microsecond). +* datetime: Combines date and time information. +* timedelta: Represents the difference between two dates or times. +* tzinfo: Provides time zone information objects. + +**Key Concepts:** + +* Naive vs. Aware: Naive datetime objects do not contain time zone information, while aware datetime objects do. +* Immutability: date and time objects are immutable; once created, they cannot be changed. + +Example: +```bash +python +Copy code +import datetime +# Get the current date and time +now = datetime.datetime.now() +print("Current date and time:", now) +``` + +## 2. Formatting Dates and Times +Formatting involves converting datetime objects into human-readable strings. This is achieved using the strftime method, which stands for "string format time." +You can specify various format codes to dictate how the output string should be structured. + +**Common Format Codes:** + +* %Y: Year with century (e.g., 2024) +* %m: Month as a zero-padded decimal number (e.g., 01) +* %d: Day of the month as a zero-padded decimal number (e.g., 15) +* %H: Hour (24-hour clock) as a zero-padded decimal number (e.g., 13) +* %M: Minute as a zero-padded decimal number (e.g., 45) +* %S: Second as a zero-padded decimal number (e.g., 30) + +Example: +```bash +python +Copy code +import datetime + +now = datetime.datetime.now() +formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") +print("Formatted current date and time:", formatted_now) +``` + +## 3. Parsing Dates and Times +Parsing is the process of converting strings representing dates and times into datetime objects. The strptime method, which stands for "string parse time," +allows you to specify the format of the input string. + +Example: +```bash +python +Copy code +import datetime + +date_string = "2024-05-15 13:45:30" +date_object = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S") +print("Parsed date and time:", date_object) +``` + +## 4. Working with Time Differences +The timedelta class is used to represent the difference between two datetime objects. This is useful for calculations involving durations, such as finding the +number of days between two dates or adding a certain period to a date. + +Example: +```bash +python +Copy code +import datetime + +date1 = datetime.datetime(2024, 5, 15, 12, 0, 0) +date2 = datetime.datetime(2024, 5, 20, 14, 30, 0) + +difference = date2 - date1 +print("Difference:", difference) +print("Days:", difference.days) +print("Total seconds:", difference.total_seconds()) +``` + +## 5. Time Zones +Time zone handling in Python is facilitated by the pytz library. It allows you to convert naive datetime objects into timezone-aware objects and perform +operations across different time zones. + +**Key Concepts:** + +* Timezone-aware: A datetime object that includes timezone information. +* Localization: The process of associating a naive datetime with a time zone. + +Example: +```bash +python +Copy code +import datetime +import pytz + +# Define a timezone +tz = pytz.timezone('Asia/Kolkata') + +# Get the current time in a specific timezone +now = datetime.datetime.now(tz) +print("Current time in Asia/Kolkata:", now) +``` + +## 6. Date Arithmetic +Date arithmetic involves performing operations like addition or subtraction on date or datetime objects using timedelta. This is useful for calculating future +or past dates based on a given date. + +Example: +```bash +python +Copy code +import datetime + +today = datetime.date.today() +future_date = today + datetime.timedelta(days=10) +print("Date after 10 days:", future_date) +``` + +## Summary +Python’s datetime module and the pytz library provide comprehensive tools for working with dates, times, and time zones. They enable you to perform a wide range +of operations, from basic date manipulations to complex time zone conversions. From affc013943c380df51e90c08553573a6da46a143 Mon Sep 17 00:00:00 2001 From: Pradnya <116059908+PradnyaGaitonde@users.noreply.github.com> Date: Tue, 21 May 2024 21:55:23 +0530 Subject: [PATCH 13/17] Update index.md Added index for dates and times --- contrib/advanced-python/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/advanced-python/index.md b/contrib/advanced-python/index.md index 5ea5081..bf377fc 100644 --- a/contrib/advanced-python/index.md +++ b/contrib/advanced-python/index.md @@ -1,3 +1,4 @@ # List of sections - [Decorators/\*args/**kwargs](decorator-kwargs-args.md) +- [Working with Dates & Times in Python](dates_and_times.md) From 2967206c16c69227da131aa560efe0831148bc12 Mon Sep 17 00:00:00 2001 From: Pradnya <116059908+PradnyaGaitonde@users.noreply.github.com> Date: Tue, 21 May 2024 22:01:17 +0530 Subject: [PATCH 14/17] Create regular_expressions.md Added content for regular expressions in python --- .../advanced-python/regular_expressions.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 contrib/advanced-python/regular_expressions.md diff --git a/contrib/advanced-python/regular_expressions.md b/contrib/advanced-python/regular_expressions.md new file mode 100644 index 0000000..65ff2c2 --- /dev/null +++ b/contrib/advanced-python/regular_expressions.md @@ -0,0 +1,96 @@ +## Regular Expressions in Python +Regular expressions (regex) are a powerful tool for pattern matching and text manipulation. +Python's re module provides comprehensive support for regular expressions, enabling efficient text processing and validation. + +## 1. Introduction to Regular Expressions +A regular expression is a sequence of characters defining a search pattern. Common use cases include validating input, searching within text, and extracting +specific patterns. + +## 2. Basic Syntax +Literal Characters: Match exact characters (e.g., abc matches "abc"). +Metacharacters: Special characters like ., *, ?, +, ^, $, [ ], and | used to build patterns. + +**Common Metacharacters:** + +* .: Any character except newline. +* ^: Start of the string. +* $: End of the string. +* *: 0 or more repetitions. +* +: 1 or more repetitions. +* ?: 0 or 1 repetition. +* []: Any one character inside brackets (e.g., [a-z]). +* |: Either the pattern before or after. + +## 3. Using the re Module + +**Key functions in the re module:** + +* re.match(): Checks for a match at the beginning of the string. +* re.search(): Searches for a match anywhere in the string. +* re.findall(): Returns a list of all matches. +* re.sub(): Replaces matches with a specified string. + +Examples: +```bash +import re + +# Match at the beginning +print(re.match(r'\d+', '123abc').group()) # Output: 123 + +# Search anywhere +print(re.search(r'\d+', 'abc123').group()) # Output: 123 + +# Find all matches +print(re.findall(r'\d+', 'abc123def456')) # Output: ['123', '456'] + +# Substitute matches +print(re.sub(r'\d+', '#', 'abc123def456')) # Output: abc#def# +``` + +## 4. Compiling Regular Expressions +Compiling regular expressions improves performance for repeated use. + +Example: +```bash +import re + +pattern = re.compile(r'\d+') +print(pattern.match('123abc').group()) # Output: 123 +print(pattern.search('abc123').group()) # Output: 123 +print(pattern.findall('abc123def456')) # Output: ['123', '456'] +``` + +## 5. Groups and Capturing +Parentheses () group and capture parts of the match. + +Example: +```bash +import re + +match = re.match(r'(\d{3})-(\d{2})-(\d{4})', '123-45-6789') +if match: + print(match.group()) # Output: 123-45-6789 + print(match.group(1)) # Output: 123 + print(match.group(2)) # Output: 45 + print(match.group(3)) # Output: 6789 +``` + +## 6. Special Sequences +Special sequences are shortcuts for common patterns: + +* \d: Any digit. +* \D: Any non-digit. +* \w: Any alphanumeric character. +* \W: Any non-alphanumeric character. +* \s: Any whitespace character. +* \S: Any non-whitespace character. +Example: +```bash +import re + +print(re.search(r'\w+@\w+\.\w+', 'Contact: support@example.com').group()) # Output: support@example.com +``` + +## Summary +Regular expressions are a versatile tool for text processing in Python. The re module offers powerful functions and metacharacters for pattern matching, +searching, and manipulation, making it an essential skill for handling complex text processing tasks. From d44f8fc253ae6a74af3894ecd77ceb2ef5f01adf Mon Sep 17 00:00:00 2001 From: Pradnya <116059908+PradnyaGaitonde@users.noreply.github.com> Date: Tue, 21 May 2024 22:03:27 +0530 Subject: [PATCH 15/17] Update index.md added index for regular --- contrib/advanced-python/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/advanced-python/index.md b/contrib/advanced-python/index.md index 5ea5081..ebb567a 100644 --- a/contrib/advanced-python/index.md +++ b/contrib/advanced-python/index.md @@ -1,3 +1,4 @@ # List of sections - [Decorators/\*args/**kwargs](decorator-kwargs-args.md) +- [Regular Expressions in Python](regular_expressions.md) From d7dc67b678124cd54a93c5b917af9d7a903fb82d Mon Sep 17 00:00:00 2001 From: Pradnya <116059908+PradnyaGaitonde@users.noreply.github.com> Date: Tue, 21 May 2024 22:05:01 +0530 Subject: [PATCH 16/17] Update dates_and_times.md --- contrib/advanced-python/dates_and_times.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/contrib/advanced-python/dates_and_times.md b/contrib/advanced-python/dates_and_times.md index f599e26..983f6b2 100644 --- a/contrib/advanced-python/dates_and_times.md +++ b/contrib/advanced-python/dates_and_times.md @@ -19,8 +19,6 @@ The datetime module supplies classes for manipulating dates and times. The main Example: ```bash -python -Copy code import datetime # Get the current date and time now = datetime.datetime.now() @@ -42,8 +40,6 @@ You can specify various format codes to dictate how the output string should be Example: ```bash -python -Copy code import datetime now = datetime.datetime.now() @@ -57,8 +53,6 @@ allows you to specify the format of the input string. Example: ```bash -python -Copy code import datetime date_string = "2024-05-15 13:45:30" @@ -72,8 +66,6 @@ number of days between two dates or adding a certain period to a date. Example: ```bash -python -Copy code import datetime date1 = datetime.datetime(2024, 5, 15, 12, 0, 0) @@ -96,8 +88,6 @@ operations across different time zones. Example: ```bash -python -Copy code import datetime import pytz @@ -115,8 +105,6 @@ or past dates based on a given date. Example: ```bash -python -Copy code import datetime today = datetime.date.today() From 5e95059765b6cb99498c1302b94f68c8d5ee482c Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Thu, 23 May 2024 02:57:11 +0530 Subject: [PATCH 17/17] Update dice_roller.md --- contrib/mini-projects/dice_roller.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/contrib/mini-projects/dice_roller.md b/contrib/mini-projects/dice_roller.md index 6e1b793..0f4e5f9 100644 --- a/contrib/mini-projects/dice_roller.md +++ b/contrib/mini-projects/dice_roller.md @@ -1,14 +1,18 @@ -Dice Roller -
-The aim of this project is to replicate a dice and generate a random number from the numbers 1 to 6.

+## Dice Roller + +The aim of this project is to replicate a dice and generate a random number from the numbers 1 to 6. + For this first we will import the random library which will help make random choices. + ``` import random def dice(): dice_no = random.choice([1,2,3,4,5,6]) return "You got " + str(dice_no) ``` -The above snippet of code defines a function called "dice( )" which makes the random choice and returns the number that is generated. + +The above snippet of code defines a function called `dice()` which makes the random choice and returns the number that is generated. + ``` def roll_dice(): print("Hey Guys, you will now roll a single dice using Python!") @@ -24,6 +28,9 @@ def roll_dice(): print("Thanks for rolling the dice.") roll_dice() ``` -The above code defines a function called "roll_dice( )" which interacts with the user.
-It prompts the user to give an input and if the input is k,the code proceeds further to generate a random number or gives the message of invalid input and asks the user to try again.
-After the dice has been rolled once, the function asks the user whether they want a reroll in the form of a yes or no question.The dice is rolled again if the user gives 'yes' as an answer and exits the code if the user replies with anything other than yes. + +The above code defines a function called `roll_dice()` which interacts with the user. + +It prompts the user to give an input and if the input is `k`,the code proceeds further to generate a random number or gives the message of invalid input and asks the user to try again. + +After the dice has been rolled once, the function asks the user whether they want a reroll in the form of a `yes` or `no` question. The dice is rolled again if the user gives `yes` as an answer and exits the code if the user replies with anything other than yes.