From 77ff4196587752150a8b29a8db6ceae0bddb4fe9 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Sun, 12 May 2024 20:53:09 +0530 Subject: [PATCH 1/9] 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 82596a2f..52e183dc 100644 --- a/contrib/mini-projects/index.md +++ b/contrib/mini-projects/index.md @@ -1,3 +1,3 @@ # List of sections -- [Section title](filename.md) +- [Basic Quiz Game](Quiz_game.md) From df8430346ea7d829a730d32b74ddd1fc5d2be690 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Sun, 12 May 2024 20:53:59 +0530 Subject: [PATCH 2/9] Add files via upload --- contrib/mini-projects/Quiz_game.md | 315 +++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 contrib/mini-projects/Quiz_game.md diff --git a/contrib/mini-projects/Quiz_game.md b/contrib/mini-projects/Quiz_game.md new file mode 100644 index 00000000..844ec1fb --- /dev/null +++ b/contrib/mini-projects/Quiz_game.md @@ -0,0 +1,315 @@ +# Basic Quiz Game + +This is a simple Python script for a basic quiz game. It allows users to choose from different genres of quizzes including Sports, Entertainment, Physics, Chemistry, and Biology. The user selects a genre, and then answers multiple-choice questions related to that genre. After answering all the questions, the user's score is displayed. + +```python + +import time + +print("******************WELCOME TO ULTIMATE QUIZ GAME******************") + +flag = 0 + +while flag == 0: + +    print("Select your genre of quiz") + +    print(''' + +    1 .Sports + +    2. Entertainment + +    3. Physics + +    4. Chemistry + +    5. Biology + +    6. Exit + +    ''') + +    genre = input("") + +    if genre == "1": + +        # Sports Quiz + +        print("Lets start the quiz.....") + +        time.sleep(1.5) + +        print("3") + +        time.sleep(1.5) + +        print("2") + +        time.sleep(1.5) + +        print("1") + +        print("Welcome to the Sports Quiz!") + +        score = 0 + +        # Question 1 + +        print("\nQuestion 1: In which sport would you perform a 'slam dunk'?") + +        print("1. Basketball") + +        print("2. Soccer") + +        print("3. Tennis") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 2 + +        print("\nQuestion 2: Which sport is known as the 'king of sports' or 'king of games'?") + +        print("1. Soccer") + +        print("2. Tennis") + +        print("3. Cricket") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "3": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 3 + +        print("\nQuestion 3: How many players are there on a baseball team?") + +        print("1. 9") + +        print("2. 11") + +        print("3. 7") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 4 + +        print("\nQuestion 4: Who holds the record for the most Grand Slam titles in tennis (men's singles)?") + +        print("1. Roger Federer") + +        print("2. Rafael Nadal") + +        print("3. Novak Djokovic") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 5 + +        print("\nQuestion 5: How many rings are there on the Olympic flag?") + +        print("1. 6") + +        print("2. 5") + +        print("3. 7") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "2": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Print score + +        print("\nYour score is: {}/5".format(score)) + +        time.sleep(2) + +    elif genre == "2": + +        # Entertainment Quiz + +        print("Let's start the Entertainment.....") + +        time.sleep(1.5) + +        print("3") + +        time.sleep(1.5) + +        print("2") + +        time.sleep(1.5) + +        print("1") + +        print("Welcome to the Mixed Quiz!") + +        score = 0 + +        # Question 1 (Marvel) + +        print("\nQuestion 1: What is the real name of Iron Man?") + +        print("1. Tony Stark") + +        print("2. Steve Rogers") + +        print("3. Bruce Banner") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 2 (Bollywood) + +        print("\nQuestion 2: Who played the lead role in the Bollywood movie 'Dangal'?") + +        print("1. Aamir Khan") + +        print("2. Salman Khan") + +        print("3. Shah Rukh Khan") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 3 (Marvel) + +        print("\nQuestion 3: What is the real name of Captain America?") + +        print("1. Tony Stark") + +        print("2. Steve Rogers") + +        print("3. Bruce Banner") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "2": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 4 (Bollywood) + +        print("\nQuestion 4: Who directed the Bollywood movie 'Gully Boy'?") + +        print("1. Karan Johar") + +        print("2. Zoya Akhtar") + +        print("3. Anurag Kashyap") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "2": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Question 5 (Mixed) + +        print("\nQuestion 5: What is the name of the actor who played the character 'Wolverine' in the X-Men movies?") + +        print("1. Hugh Jackman") + +        print("2. Robert Downey Jr.") + +        print("3. Chris Evans") + +        user_answer = input("Your answer (Enter 1, 2, or 3): ") + +        if user_answer == "1": + +            print("Correct!") + +            score += 1 + +        else: + +            print("Incorrect!") + +        # Print score + +        print("\nYour score is: {}/5".format(score)) + +        time.sleep(2) + +    elif genre == "6": + +        flag = 1 + +``` \ No newline at end of file From 8ba44567afc953cd11a9ba4eb7ac29548b8ac714 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Sun, 12 May 2024 21:44:07 +0530 Subject: [PATCH 3/9] Update Quiz_game.md --- contrib/mini-projects/Quiz_game.md | 270 ++++++----------------------- 1 file changed, 53 insertions(+), 217 deletions(-) diff --git a/contrib/mini-projects/Quiz_game.md b/contrib/mini-projects/Quiz_game.md index 844ec1fb..076c933c 100644 --- a/contrib/mini-projects/Quiz_game.md +++ b/contrib/mini-projects/Quiz_game.md @@ -1,6 +1,6 @@ # Basic Quiz Game -This is a simple Python script for a basic quiz game. It allows users to choose from different genres of quizzes including Sports, Entertainment, Physics, Chemistry, and Biology. The user selects a genre, and then answers multiple-choice questions related to that genre. After answering all the questions, the user's score is displayed. +This is a simple quiz game where players can choose from different genres of quizzes such as Sports, Entertainment, Physics, Chemistry, and Biology. Each genre contains five questions related to the chosen category. Players input their answers, and the program provides feedback on whether the answer is correct or incorrect along with the final score. ```python @@ -16,7 +16,7 @@ while flag == 0:     print(''' -    1 .Sports +    1. Sports     2. Entertainment @@ -32,149 +32,13 @@ while flag == 0:     genre = input("") -    if genre == "1": +    if genre == "6": -        # Sports Quiz - -        print("Lets start the quiz.....") - -        time.sleep(1.5) - -        print("3") - -        time.sleep(1.5) - -        print("2") - -        time.sleep(1.5) - -        print("1") - -        print("Welcome to the Sports Quiz!") - -        score = 0 - -        # Question 1 - -        print("\nQuestion 1: In which sport would you perform a 'slam dunk'?") - -        print("1. Basketball") - -        print("2. Soccer") - -        print("3. Tennis") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "1": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Question 2 - -        print("\nQuestion 2: Which sport is known as the 'king of sports' or 'king of games'?") - -        print("1. Soccer") - -        print("2. Tennis") - -        print("3. Cricket") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "3": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Question 3 - -        print("\nQuestion 3: How many players are there on a baseball team?") - -        print("1. 9") - -        print("2. 11") - -        print("3. 7") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "1": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Question 4 - -        print("\nQuestion 4: Who holds the record for the most Grand Slam titles in tennis (men's singles)?") - -        print("1. Roger Federer") - -        print("2. Rafael Nadal") - -        print("3. Novak Djokovic") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "1": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Question 5 - -        print("\nQuestion 5: How many rings are there on the Olympic flag?") - -        print("1. 6") - -        print("2. 5") - -        print("3. 7") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "2": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Print score - -        print("\nYour score is: {}/5".format(score)) - -        time.sleep(2) - -    elif genre == "2": +        flag = 1 -        # Entertainment Quiz +    elif genre in ["1", "2", "3", "4", "5"]: -        print("Let's start the Entertainment.....") +        print(f"Let's start the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz.....")         time.sleep(1.5) @@ -188,128 +52,100 @@ while flag == 0:         print("1") -        print("Welcome to the Mixed Quiz!") +        print(f"Welcome to the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz!")         score = 0 -        # Question 1 (Marvel) - -        print("\nQuestion 1: What is the real name of Iron Man?") - -        print("1. Tony Stark") - -        print("2. Steve Rogers") - -        print("3. Bruce Banner") +        # Questions, options, and answers for each genre -        user_answer = input("Your answer (Enter 1, 2, or 3): ") +        quiz_data = [ -        if user_answer == "1": +            # Sports -            print("Correct!") +            [("In which sport would you perform a 'slam dunk'?", ["1. Basketball", "2. Soccer", "3. Tennis"], "1"), -            score += 1 +             ("Which sport is known as the 'king of sports' or 'king of games'?", ["1. Soccer", "2. Tennis", "3. Cricket"], "3"), -        else: +             ("How many players are there on a baseball team?", ["1. 9", "2. 11", "3. 7"], "1"), -            print("Incorrect!") +             ("Who holds the record for the most Grand Slam titles in tennis (men's singles)?", ["1. Roger Federer", "2. Rafael Nadal", "3. Novak Djokovic"], "1"), -        # Question 2 (Bollywood) +             ("How many rings are there on the Olympic flag?", ["1. 6", "2. 5", "3. 7"], "2")], -        print("\nQuestion 2: Who played the lead role in the Bollywood movie 'Dangal'?") +            # Entertainment -        print("1. Aamir Khan") +            [("What is the real name of Iron Man?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "1"), -        print("2. Salman Khan") +             ("Who played the lead role in the Bollywood movie 'Dangal'?", ["1. Aamir Khan", "2. Salman Khan", "3. Shah Rukh Khan"], "1"), -        print("3. Shah Rukh Khan") +             ("What is the real name of Captain America?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "2"), -        user_answer = input("Your answer (Enter 1, 2, or 3): ") +             ("Who directed the Bollywood movie 'Gully Boy'?", ["1. Karan Johar", "2. Zoya Akhtar", "3. Anurag Kashyap"], "2"), -        if user_answer == "1": +             ("What is the name of the actor who played the character 'Wolverine' in the X-Men movies?", ["1. Hugh Jackman", "2. Robert Downey Jr.", "3. Chris Evans"], "1")], -            print("Correct!") +            # Physics -            score += 1 +            [("What is the SI unit of force?", ["1. Newton", "2. Joule", "3. Watt"], "1"), -        else: +             ("What is the speed of light in a vacuum?", ["1. 299,792,458 m/s", "2. 3.00 × 10^8 m/s", "3. Both options are correct"], "3"), -            print("Incorrect!") +             ("What is the acceleration due to gravity on the surface of the Earth?", ["1. 9.8 m/s^2", "2. 10 m/s^2", "3. 9.81 m/s^2"], "3"), -        # Question 3 (Marvel) +             ("What is the unit of electric current?", ["1. Ampere", "2. Volt", "3. Ohm"], "1"), -        print("\nQuestion 3: What is the real name of Captain America?") +             ("What is the SI unit of power?", ["1. Watt", "2. Joule", "3. Newton"], "1")], -        print("1. Tony Stark") +            # Chemistry -        print("2. Steve Rogers") +            [("What is the chemical symbol for oxygen?", ["1. O", "2. Ox", "3. Os"], "1"), -        print("3. Bruce Banner") +             ("What is the pH value of pure water at room temperature?", ["1. 6", "2. 7", "3. 8"], "2"), -        user_answer = input("Your answer (Enter 1, 2, or 3): ") +             ("Which element has the atomic number 6?", ["1. Nitrogen", "2. Carbon", "3. Oxygen"], "2"), -        if user_answer == "2": +             ("What is the chemical formula for table salt?", ["1. NaCl", "2. HCl", "3. NaOH"], "1"), -            print("Correct!") +             ("What is the process called when a gas turns into a liquid?", ["1. Evaporation", "2. Condensation", "3. Sublimation"], "2")], -            score += 1 +            # Biology -        else: +            [("What is the powerhouse of the cell?", ["1. Nucleus", "2. Mitochondria", "3. Ribosome"], "2"), -            print("Incorrect!") +             ("Which gas do plants use in photosynthesis?", ["1. Oxygen", "2. Carbon Dioxide", "3. Nitrogen"], "2"), -        # Question 4 (Bollywood) +             ("Which organ produces insulin in the human body?", ["1. Liver", "2. Kidneys", "3. Pancreas"], "3"), -        print("\nQuestion 4: Who directed the Bollywood movie 'Gully Boy'?") +             ("What is the largest organ in the human body?", ["1. Liver", "2. Skin", "3. Heart"], "2"), -        print("1. Karan Johar") +             ("What is the basic unit of heredity?", ["1. Chromosome", "2. Gene", "3. Allele"], "2")] -        print("2. Zoya Akhtar") +        ] -        print("3. Anurag Kashyap") +        for question, options, answer in quiz_data[int(genre) - 1]: -        user_answer = input("Your answer (Enter 1, 2, or 3): ") +            print(f"\nQuestion: {question}") -        if user_answer == "2": +            for option in options: -            print("Correct!") +                print(option) -            score += 1 +            user_answer = input("Your answer (Enter 1, 2, or 3): ") -        else: +            if user_answer == answer: -            print("Incorrect!") +                print("Correct!") -        # Question 5 (Mixed) +                score += 1 -        print("\nQuestion 5: What is the name of the actor who played the character 'Wolverine' in the X-Men movies?") +            else: -        print("1. Hugh Jackman") +                print("Incorrect!") -        print("2. Robert Downey Jr.") +        # Print final score -        print("3. Chris Evans") - -        user_answer = input("Your answer (Enter 1, 2, or 3): ") - -        if user_answer == "1": - -            print("Correct!") - -            score += 1 - -        else: - -            print("Incorrect!") - -        # Print score - -        print("\nYour score is: {}/5".format(score)) +        print(f"\nYour score is: {score}/5")         time.sleep(2) -    elif genre == "6": - -        flag = 1 - -``` \ No newline at end of file +``` From 3ad0d5b0444ceb47da92c11fda4f7a53f9abfc57 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Sun, 12 May 2024 21:49:44 +0530 Subject: [PATCH 4/9] Update Quiz_game.md --- contrib/mini-projects/Quiz_game.md | 217 +++++++++++------------------ 1 file changed, 81 insertions(+), 136 deletions(-) diff --git a/contrib/mini-projects/Quiz_game.md b/contrib/mini-projects/Quiz_game.md index 076c933c..9e039887 100644 --- a/contrib/mini-projects/Quiz_game.md +++ b/contrib/mini-projects/Quiz_game.md @@ -9,143 +9,88 @@ import time print("******************WELCOME TO ULTIMATE QUIZ GAME******************") flag = 0 - while flag == 0: + # Display menu for selecting quiz genre + print("Select your genre of quiz") + print(''' + 1. Sports + 2. Entertainment + 3. Physics + 4. Chemistry + 5. Biology + 6. Exit + ''') + genre = input("") + + # If user chooses to exit + if genre == "6": + flag = 1 + # If user chooses a quiz genre + elif genre in ["1", "2", "3", "4", "5"]: + print(f"Let's start the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz.....") + time.sleep(1.5) + print("3") + time.sleep(1.5) + print("2") + time.sleep(1.5) + print("1") + print(f"Welcome to the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz!") + + score = 0 + + # Questions, options, and answers for each genre + quiz_data = [ + # Sports + [("In which sport would you perform a 'slam dunk'?", ["1. Basketball", "2. Soccer", "3. Tennis"], "1"), + ("Which sport is known as the 'king of sports' or 'king of games'?", ["1. Soccer", "2. Tennis", "3. Cricket"], "3"), + ("How many players are there on a baseball team?", ["1. 9", "2. 11", "3. 7"], "1"), + ("Who holds the record for the most Grand Slam titles in tennis (men's singles)?", ["1. Roger Federer", "2. Rafael Nadal", "3. Novak Djokovic"], "1"), + ("How many rings are there on the Olympic flag?", ["1. 6", "2. 5", "3. 7"], "2")], + + # Entertainment + [("What is the real name of Iron Man?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "1"), + ("Who played the lead role in the Bollywood movie 'Dangal'?", ["1. Aamir Khan", "2. Salman Khan", "3. Shah Rukh Khan"], "1"), + ("What is the real name of Captain America?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "2"), + ("Who directed the Bollywood movie 'Gully Boy'?", ["1. Karan Johar", "2. Zoya Akhtar", "3. Anurag Kashyap"], "2"), + ("What is the name of the actor who played the character 'Wolverine' in the X-Men movies?", ["1. Hugh Jackman", "2. Robert Downey Jr.", "3. Chris Evans"], "1")], + + # Physics + [("What is the SI unit of force?", ["1. Newton", "2. Joule", "3. Watt"], "1"), + ("What is the speed of light in a vacuum?", ["1. 299,792,458 m/s", "2. 3.00 × 10^8 m/s", "3. Both options are correct"], "3"), + ("What is the acceleration due to gravity on the surface of the Earth?", ["1. 9.8 m/s^2", "2. 10 m/s^2", "3. 9.81 m/s^2"], "3"), + ("What is the unit of electric current?", ["1. Ampere", "2. Volt", "3. Ohm"], "1"), + ("What is the SI unit of power?", ["1. Watt", "2. Joule", "3. Newton"], "1")], + + # Chemistry + [("What is the chemical symbol for oxygen?", ["1. O", "2. Ox", "3. Os"], "1"), + ("What is the pH value of pure water at room temperature?", ["1. 6", "2. 7", "3. 8"], "2"), + ("Which element has the atomic number 6?", ["1. Nitrogen", "2. Carbon", "3. Oxygen"], "2"), + ("What is the chemical formula for table salt?", ["1. NaCl", "2. HCl", "3. NaOH"], "1"), + ("What is the process called when a gas turns into a liquid?", ["1. Evaporation", "2. Condensation", "3. Sublimation"], "2")], + + # Biology + [("What is the powerhouse of the cell?", ["1. Nucleus", "2. Mitochondria", "3. Ribosome"], "2"), + ("Which gas do plants use in photosynthesis?", ["1. Oxygen", "2. Carbon Dioxide", "3. Nitrogen"], "2"), + ("Which organ produces insulin in the human body?", ["1. Liver", "2. Kidneys", "3. Pancreas"], "3"), + ("What is the largest organ in the human body?", ["1. Liver", "2. Skin", "3. Heart"], "2"), + ("What is the basic unit of heredity?", ["1. Chromosome", "2. Gene", "3. Allele"], "2")] + ] + + # Iterate over each question, display options, and check answers + for question, options, answer in quiz_data[int(genre) - 1]: + print(f"\nQuestion: {question}") + for option in options: + print(option) + user_answer = input("Your answer (Enter 1, 2, or 3): ") + if user_answer == answer: + print("Correct!") + score += 1 + else: + print("Incorrect!") + + # Print final score + print(f"\nYour score is: {score}/5") + time.sleep(2) # Pause for 2 seconds before returning to the menu -    print("Select your genre of quiz") - -    print(''' - -    1. Sports - -    2. Entertainment - -    3. Physics - -    4. Chemistry - -    5. Biology - -    6. Exit - -    ''') - -    genre = input("") - -    if genre == "6": - -        flag = 1 - -    elif genre in ["1", "2", "3", "4", "5"]: - -        print(f"Let's start the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz.....") - -        time.sleep(1.5) - -        print("3") - -        time.sleep(1.5) - -        print("2") - -        time.sleep(1.5) - -        print("1") - -        print(f"Welcome to the {['Sports', 'Entertainment', 'Physics', 'Chemistry', 'Biology'][int(genre) - 1]} Quiz!") - -        score = 0 - -        # Questions, options, and answers for each genre - -        quiz_data = [ - -            # Sports - -            [("In which sport would you perform a 'slam dunk'?", ["1. Basketball", "2. Soccer", "3. Tennis"], "1"), - -             ("Which sport is known as the 'king of sports' or 'king of games'?", ["1. Soccer", "2. Tennis", "3. Cricket"], "3"), - -             ("How many players are there on a baseball team?", ["1. 9", "2. 11", "3. 7"], "1"), - -             ("Who holds the record for the most Grand Slam titles in tennis (men's singles)?", ["1. Roger Federer", "2. Rafael Nadal", "3. Novak Djokovic"], "1"), - -             ("How many rings are there on the Olympic flag?", ["1. 6", "2. 5", "3. 7"], "2")], - -            # Entertainment - -            [("What is the real name of Iron Man?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "1"), - -             ("Who played the lead role in the Bollywood movie 'Dangal'?", ["1. Aamir Khan", "2. Salman Khan", "3. Shah Rukh Khan"], "1"), - -             ("What is the real name of Captain America?", ["1. Tony Stark", "2. Steve Rogers", "3. Bruce Banner"], "2"), - -             ("Who directed the Bollywood movie 'Gully Boy'?", ["1. Karan Johar", "2. Zoya Akhtar", "3. Anurag Kashyap"], "2"), - -             ("What is the name of the actor who played the character 'Wolverine' in the X-Men movies?", ["1. Hugh Jackman", "2. Robert Downey Jr.", "3. Chris Evans"], "1")], - -            # Physics - -            [("What is the SI unit of force?", ["1. Newton", "2. Joule", "3. Watt"], "1"), - -             ("What is the speed of light in a vacuum?", ["1. 299,792,458 m/s", "2. 3.00 × 10^8 m/s", "3. Both options are correct"], "3"), - -             ("What is the acceleration due to gravity on the surface of the Earth?", ["1. 9.8 m/s^2", "2. 10 m/s^2", "3. 9.81 m/s^2"], "3"), - -             ("What is the unit of electric current?", ["1. Ampere", "2. Volt", "3. Ohm"], "1"), - -             ("What is the SI unit of power?", ["1. Watt", "2. Joule", "3. Newton"], "1")], - -            # Chemistry - -            [("What is the chemical symbol for oxygen?", ["1. O", "2. Ox", "3. Os"], "1"), - -             ("What is the pH value of pure water at room temperature?", ["1. 6", "2. 7", "3. 8"], "2"), - -             ("Which element has the atomic number 6?", ["1. Nitrogen", "2. Carbon", "3. Oxygen"], "2"), - -             ("What is the chemical formula for table salt?", ["1. NaCl", "2. HCl", "3. NaOH"], "1"), - -             ("What is the process called when a gas turns into a liquid?", ["1. Evaporation", "2. Condensation", "3. Sublimation"], "2")], - -            # Biology - -            [("What is the powerhouse of the cell?", ["1. Nucleus", "2. Mitochondria", "3. Ribosome"], "2"), - -             ("Which gas do plants use in photosynthesis?", ["1. Oxygen", "2. Carbon Dioxide", "3. Nitrogen"], "2"), - -             ("Which organ produces insulin in the human body?", ["1. Liver", "2. Kidneys", "3. Pancreas"], "3"), - -             ("What is the largest organ in the human body?", ["1. Liver", "2. Skin", "3. Heart"], "2"), - -             ("What is the basic unit of heredity?", ["1. Chromosome", "2. Gene", "3. Allele"], "2")] - -        ] - -        for question, options, answer in quiz_data[int(genre) - 1]: - -            print(f"\nQuestion: {question}") - -            for option in options: - -                print(option) - -            user_answer = input("Your answer (Enter 1, 2, or 3): ") - -            if user_answer == answer: - -                print("Correct!") - -                score += 1 - -            else: - -                print("Incorrect!") - -        # Print final score - -        print(f"\nYour score is: {score}/5") - -        time.sleep(2) ``` From 1b2e2ddb233de1dc8369cdba67a0303a4cb35209 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Mon, 13 May 2024 09:52:06 +0530 Subject: [PATCH 5/9] Update Quiz_game.md --- contrib/mini-projects/Quiz_game.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/contrib/mini-projects/Quiz_game.md b/contrib/mini-projects/Quiz_game.md index 9e039887..c9dcc618 100644 --- a/contrib/mini-projects/Quiz_game.md +++ b/contrib/mini-projects/Quiz_game.md @@ -2,10 +2,25 @@ This is a simple quiz game where players can choose from different genres of quizzes such as Sports, Entertainment, Physics, Chemistry, and Biology. Each genre contains five questions related to the chosen category. Players input their answers, and the program provides feedback on whether the answer is correct or incorrect along with the final score. +## Prerequisite +1. Basic Python +2. Decision Control +3. Nested Loops +4. List data structure +## Source Code + +### Importing necessary libraries + ```python import time +``` + +### Main Code + +```python + print("******************WELCOME TO ULTIMATE QUIZ GAME******************") flag = 0 @@ -38,6 +53,10 @@ while flag == 0: score = 0 +``` + +### Creating list of questions, options and correct answer +```python # Questions, options, and answers for each genre quiz_data = [ # Sports @@ -76,6 +95,12 @@ while flag == 0: ("What is the basic unit of heredity?", ["1. Chromosome", "2. Gene", "3. Allele"], "2")] ] +``` + +### Iterating over each item in the list above based on selected genre + +```pyhton + # Iterate over each question, display options, and check answers for question, options, answer in quiz_data[int(genre) - 1]: print(f"\nQuestion: {question}") @@ -87,7 +112,10 @@ while flag == 0: score += 1 else: print("Incorrect!") +``` +### Giving the final score +```python # Print final score print(f"\nYour score is: {score}/5") time.sleep(2) # Pause for 2 seconds before returning to the menu From 397137ed0287c956144030a489067a218e414728 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Wed, 15 May 2024 19:00:14 +0530 Subject: [PATCH 6/9] Create Matplotlib.md --- contrib/plotting-visualization/Matplotlib.md | 351 +++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 contrib/plotting-visualization/Matplotlib.md diff --git a/contrib/plotting-visualization/Matplotlib.md b/contrib/plotting-visualization/Matplotlib.md new file mode 100644 index 00000000..b0536e42 --- /dev/null +++ b/contrib/plotting-visualization/Matplotlib.md @@ -0,0 +1,351 @@ +# Comprehensive Matplotlib Tutorial + +Matplotlib is a powerful plotting library for Python, widely used for data visualization. This tutorial will guide you through everything from basic plotting to more advanced customization options, starting from scratch. + +### Introduction to Matplotlib + +Matplotlib is versatile and can create static, animated, and interactive visualizations. It's especially useful for data analysis and is widely used in scientific and engineering communities. + +![Alt text](https://i.imgur.com/9i806Rh.png "Introduction") + +### Installation + +You can install Matplotlib using pip. Open your terminal or command prompt and run: + +```bash + +pip install matplotlib + +``` + +### Basic Concepts + +#### Figure and Axes + +In Matplotlib, the `Figure` is the overall window or page that everything is drawn on, while `Axes` are the individual plots or graphs within the `Figure`. + +#### Plotting a Simple Graph + +Here's a basic example of how to plot a simple line graph: + +```python + +import matplotlib.pyplot as plt + +# Sample data + +x = [1, 2, 3, 4, 5] + +y = [2, 3, 5, 7, 11] + +# Create a plot + +plt.plot(x, y) + +# Show the plot + +plt.show() + +``` + +This code will display a simple line plot of the given data. + +![Alt text](https://www.w3schools.com/python/img_matplotlib_plotting1.png "Introduction") + +### Customizing Plots + +#### Titles and Labels + +You can add titles and labels to your plots to make them more informative: + +```python + +plt.plot(x, y) + +# Adding title and labels + +plt.title('Sample Line Plot') + +plt.xlabel('X-axis Label') + +plt.ylabel('Y-axis Label') + +plt.show() + +``` + +#### Legends + +Legends help in identifying different plots on the same graph. Here's how to add them: + +```python + +# Sample data for two lines + +x = [1, 2, 3, 4, 5] + +y1 = [2, 3, 5, 7, 11] + +y2 = [1, 4, 6, 8, 10] + +# Plotting two lines + +plt.plot(x, y1, label='Prime Numbers') + +plt.plot(x, y2, label='Composite Numbers') + +# Adding legend + +plt.legend() + +plt.show() + +``` + +#### Colors and Styles + +You can customize the appearance of your plots with colors and line styles: + +```python + +# Different styles + +plt.plot(x, y1, color='blue', linestyle='-', marker='o', label='Prime') + +plt.plot(x, y2, color='red', linestyle='--', marker='x', label='Composite') + +plt.legend() + +plt.show() + +``` + +![Alt text](https://www.includehelp.com/python/images/line-plot.jpg "Introduction") + +### Types of Plots + +#### Line Plots + +Line plots are useful for showing trends over time or continuous data: + +```python + +plt.plot(x, y) + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_line_red.png) "Introduction") + +#### Scatter Plots + +Scatter plots are used to show the relationship between two sets of data: + +```python + +plt.scatter(x, y) + +plt.show() + +``` +![Alt text](https://www.w3schools.com/python/img_scatterplot.png "Introduction") + +#### Bar Plots + +Bar plots are great for categorical data comparison: + +```python + +categories = ['A', 'B', 'C', 'D', 'E'] + +values = [5, 7, 3, 8, 6] + +plt.bar(categories, values) + +plt.show() + +``` +![Alt text](https://www.w3schools.com/python/img_matplotlib_bars1.png "Introduction") + +#### Histograms + +Histograms are used to show the distribution of a dataset: + +```python + +import numpy as np + +data = np.random.randn(1000) + +plt.hist(data, bins=30) + +plt.show() + +``` +![Alt text](https://media.geeksforgeeks.org/wp-content/uploads/20231205223137/Screenshot-2023-12-05-222229.png "Introduction") + +#### Pie Charts + +Pie charts are useful for showing proportions: + +```python + +sizes = [15, 30, 45, 10] + +labels = ['A', 'B', 'C', 'D'] + +plt.pie(sizes, labels=labels, autopct='%1.1f%%') + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_pie_labels.png "Introduction") + +### Saving and Showing Plots + +You can save your plots to a file instead of showing them: + +```python + +plt.plot(x, y) + +plt.savefig('plot.png') + +plt.show()  # Optional, to display the plot + +``` + + +### Subplots + +Subplots allow you to create multiple plots in a single figure. This is useful for comparing different datasets or visualizing multiple dimensions of the same data. + +**Basic Subplot Creation:** + +```python + +import matplotlib.pyplot as plt + +# Create a figure and an array of subplots with 2 rows and 2 columns + +fig, axs = plt.subplots(2, 2) + +# Plot different types of plots in each subplot + +axs[0, 0].plot([1, 2, 3], [1, 4, 9])  # Line plot + +axs[0, 1].scatter([1, 2, 3], [1, 4, 9])  # Scatter plot + +axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3])  # Bar plot + +axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3)  # Histogram + +# Show the figure with subplots + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_subplots1.png "Introduction") + +**Customizing Subplots:** + +You can adjust the layout and appearance of your subplots using various parameters. + +```python + +fig, axs = plt.subplots(2, 2, figsize=(10, 10), gridspec_kw={'width_ratios': [2, 1]}) + +# Adjust spacing between subplots + +fig.tight_layout(pad=3.0) + +axs[0, 0].plot([1, 2, 3], [1, 4, 9]) + +axs[0, 0].set_title('Line Plot') + +axs[0, 1].scatter([1, 2, 3], [1, 4, 9]) + +axs[0, 1].set_title('Scatter Plot') + +axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3]) + +axs[1, 0].set_title('Bar Plot') + +axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3) + +axs[1, 1].set_title('Histogram') + +plt.show() + +``` + +![Alt text](https://cdn.analyticsvidhya.com/wp-content/uploads/2024/02/example-3.png "Snapshot 3") + + +### Plotting with Pandas + +Pandas integrates seamlessly with Matplotlib, making it easier to create plots from DataFrames. Here's how you can leverage this integration. + +**Basic Pandas Plotting:** + +```python + +import pandas as pd + +# Create a DataFrame + +data = {'Category': ['A', 'B', 'C', 'D'], 'Values': [23, 45, 56, 78]} + +df = pd.DataFrame(data) + +# Plot a bar graph directly from the DataFrame + +df.plot(kind='bar', x='Category', y='Values', legend=False) + +plt.title('Bar Plot from DataFrame') + +plt.show() + +``` + +**Advanced Pandas Plotting:** + +You can create more complex plots and customize them further. + +```python + +# Create a DataFrame + +data = {'Category': ['A', 'B', 'C', 'D'], + +        'Values1': [23, 45, 56, 78], + +        'Values2': [22, 43, 55, 77]} + +df = pd.DataFrame(data) + +# Plot multiple columns + +df.plot(kind='bar', x='Category', y=['Values1', 'Values2']) + +plt.title('Multiple Columns Bar Plot') + +plt.xlabel('Category') + +plt.ylabel('Values') + +plt.legend(title='Legend') + +plt.show() + +``` + + + + +### Conclusion + +This comprehensive tutorial should give you a solid foundation in Matplotlib. You can further explore its extensive documentation and experiment with different types of plots and customizations to deepen your understanding. Happy plotting! From 153b302b90aa89012cc81ead45dcb21096ff5299 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Wed, 15 May 2024 19:05:58 +0530 Subject: [PATCH 7/9] Delete contrib/plotting-visualization/Matplotlib.md --- contrib/plotting-visualization/Matplotlib.md | 351 ------------------- 1 file changed, 351 deletions(-) delete mode 100644 contrib/plotting-visualization/Matplotlib.md diff --git a/contrib/plotting-visualization/Matplotlib.md b/contrib/plotting-visualization/Matplotlib.md deleted file mode 100644 index b0536e42..00000000 --- a/contrib/plotting-visualization/Matplotlib.md +++ /dev/null @@ -1,351 +0,0 @@ -# Comprehensive Matplotlib Tutorial - -Matplotlib is a powerful plotting library for Python, widely used for data visualization. This tutorial will guide you through everything from basic plotting to more advanced customization options, starting from scratch. - -### Introduction to Matplotlib - -Matplotlib is versatile and can create static, animated, and interactive visualizations. It's especially useful for data analysis and is widely used in scientific and engineering communities. - -![Alt text](https://i.imgur.com/9i806Rh.png "Introduction") - -### Installation - -You can install Matplotlib using pip. Open your terminal or command prompt and run: - -```bash - -pip install matplotlib - -``` - -### Basic Concepts - -#### Figure and Axes - -In Matplotlib, the `Figure` is the overall window or page that everything is drawn on, while `Axes` are the individual plots or graphs within the `Figure`. - -#### Plotting a Simple Graph - -Here's a basic example of how to plot a simple line graph: - -```python - -import matplotlib.pyplot as plt - -# Sample data - -x = [1, 2, 3, 4, 5] - -y = [2, 3, 5, 7, 11] - -# Create a plot - -plt.plot(x, y) - -# Show the plot - -plt.show() - -``` - -This code will display a simple line plot of the given data. - -![Alt text](https://www.w3schools.com/python/img_matplotlib_plotting1.png "Introduction") - -### Customizing Plots - -#### Titles and Labels - -You can add titles and labels to your plots to make them more informative: - -```python - -plt.plot(x, y) - -# Adding title and labels - -plt.title('Sample Line Plot') - -plt.xlabel('X-axis Label') - -plt.ylabel('Y-axis Label') - -plt.show() - -``` - -#### Legends - -Legends help in identifying different plots on the same graph. Here's how to add them: - -```python - -# Sample data for two lines - -x = [1, 2, 3, 4, 5] - -y1 = [2, 3, 5, 7, 11] - -y2 = [1, 4, 6, 8, 10] - -# Plotting two lines - -plt.plot(x, y1, label='Prime Numbers') - -plt.plot(x, y2, label='Composite Numbers') - -# Adding legend - -plt.legend() - -plt.show() - -``` - -#### Colors and Styles - -You can customize the appearance of your plots with colors and line styles: - -```python - -# Different styles - -plt.plot(x, y1, color='blue', linestyle='-', marker='o', label='Prime') - -plt.plot(x, y2, color='red', linestyle='--', marker='x', label='Composite') - -plt.legend() - -plt.show() - -``` - -![Alt text](https://www.includehelp.com/python/images/line-plot.jpg "Introduction") - -### Types of Plots - -#### Line Plots - -Line plots are useful for showing trends over time or continuous data: - -```python - -plt.plot(x, y) - -plt.show() - -``` - -![Alt text](https://www.w3schools.com/python/img_matplotlib_line_red.png) "Introduction") - -#### Scatter Plots - -Scatter plots are used to show the relationship between two sets of data: - -```python - -plt.scatter(x, y) - -plt.show() - -``` -![Alt text](https://www.w3schools.com/python/img_scatterplot.png "Introduction") - -#### Bar Plots - -Bar plots are great for categorical data comparison: - -```python - -categories = ['A', 'B', 'C', 'D', 'E'] - -values = [5, 7, 3, 8, 6] - -plt.bar(categories, values) - -plt.show() - -``` -![Alt text](https://www.w3schools.com/python/img_matplotlib_bars1.png "Introduction") - -#### Histograms - -Histograms are used to show the distribution of a dataset: - -```python - -import numpy as np - -data = np.random.randn(1000) - -plt.hist(data, bins=30) - -plt.show() - -``` -![Alt text](https://media.geeksforgeeks.org/wp-content/uploads/20231205223137/Screenshot-2023-12-05-222229.png "Introduction") - -#### Pie Charts - -Pie charts are useful for showing proportions: - -```python - -sizes = [15, 30, 45, 10] - -labels = ['A', 'B', 'C', 'D'] - -plt.pie(sizes, labels=labels, autopct='%1.1f%%') - -plt.show() - -``` - -![Alt text](https://www.w3schools.com/python/img_matplotlib_pie_labels.png "Introduction") - -### Saving and Showing Plots - -You can save your plots to a file instead of showing them: - -```python - -plt.plot(x, y) - -plt.savefig('plot.png') - -plt.show()  # Optional, to display the plot - -``` - - -### Subplots - -Subplots allow you to create multiple plots in a single figure. This is useful for comparing different datasets or visualizing multiple dimensions of the same data. - -**Basic Subplot Creation:** - -```python - -import matplotlib.pyplot as plt - -# Create a figure and an array of subplots with 2 rows and 2 columns - -fig, axs = plt.subplots(2, 2) - -# Plot different types of plots in each subplot - -axs[0, 0].plot([1, 2, 3], [1, 4, 9])  # Line plot - -axs[0, 1].scatter([1, 2, 3], [1, 4, 9])  # Scatter plot - -axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3])  # Bar plot - -axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3)  # Histogram - -# Show the figure with subplots - -plt.show() - -``` - -![Alt text](https://www.w3schools.com/python/img_matplotlib_subplots1.png "Introduction") - -**Customizing Subplots:** - -You can adjust the layout and appearance of your subplots using various parameters. - -```python - -fig, axs = plt.subplots(2, 2, figsize=(10, 10), gridspec_kw={'width_ratios': [2, 1]}) - -# Adjust spacing between subplots - -fig.tight_layout(pad=3.0) - -axs[0, 0].plot([1, 2, 3], [1, 4, 9]) - -axs[0, 0].set_title('Line Plot') - -axs[0, 1].scatter([1, 2, 3], [1, 4, 9]) - -axs[0, 1].set_title('Scatter Plot') - -axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3]) - -axs[1, 0].set_title('Bar Plot') - -axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3) - -axs[1, 1].set_title('Histogram') - -plt.show() - -``` - -![Alt text](https://cdn.analyticsvidhya.com/wp-content/uploads/2024/02/example-3.png "Snapshot 3") - - -### Plotting with Pandas - -Pandas integrates seamlessly with Matplotlib, making it easier to create plots from DataFrames. Here's how you can leverage this integration. - -**Basic Pandas Plotting:** - -```python - -import pandas as pd - -# Create a DataFrame - -data = {'Category': ['A', 'B', 'C', 'D'], 'Values': [23, 45, 56, 78]} - -df = pd.DataFrame(data) - -# Plot a bar graph directly from the DataFrame - -df.plot(kind='bar', x='Category', y='Values', legend=False) - -plt.title('Bar Plot from DataFrame') - -plt.show() - -``` - -**Advanced Pandas Plotting:** - -You can create more complex plots and customize them further. - -```python - -# Create a DataFrame - -data = {'Category': ['A', 'B', 'C', 'D'], - -        'Values1': [23, 45, 56, 78], - -        'Values2': [22, 43, 55, 77]} - -df = pd.DataFrame(data) - -# Plot multiple columns - -df.plot(kind='bar', x='Category', y=['Values1', 'Values2']) - -plt.title('Multiple Columns Bar Plot') - -plt.xlabel('Category') - -plt.ylabel('Values') - -plt.legend(title='Legend') - -plt.show() - -``` - - - - -### Conclusion - -This comprehensive tutorial should give you a solid foundation in Matplotlib. You can further explore its extensive documentation and experiment with different types of plots and customizations to deepen your understanding. Happy plotting! From 28712559c854cbf05a980b94f687311b71dc1e77 Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Wed, 15 May 2024 19:19:13 +0530 Subject: [PATCH 8/9] Create Matplotlib_tutorial.md --- .../Matplotlib_tutorial.md | 351 ++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 contrib/plotting-visualization/Matplotlib_tutorial.md diff --git a/contrib/plotting-visualization/Matplotlib_tutorial.md b/contrib/plotting-visualization/Matplotlib_tutorial.md new file mode 100644 index 00000000..b0536e42 --- /dev/null +++ b/contrib/plotting-visualization/Matplotlib_tutorial.md @@ -0,0 +1,351 @@ +# Comprehensive Matplotlib Tutorial + +Matplotlib is a powerful plotting library for Python, widely used for data visualization. This tutorial will guide you through everything from basic plotting to more advanced customization options, starting from scratch. + +### Introduction to Matplotlib + +Matplotlib is versatile and can create static, animated, and interactive visualizations. It's especially useful for data analysis and is widely used in scientific and engineering communities. + +![Alt text](https://i.imgur.com/9i806Rh.png "Introduction") + +### Installation + +You can install Matplotlib using pip. Open your terminal or command prompt and run: + +```bash + +pip install matplotlib + +``` + +### Basic Concepts + +#### Figure and Axes + +In Matplotlib, the `Figure` is the overall window or page that everything is drawn on, while `Axes` are the individual plots or graphs within the `Figure`. + +#### Plotting a Simple Graph + +Here's a basic example of how to plot a simple line graph: + +```python + +import matplotlib.pyplot as plt + +# Sample data + +x = [1, 2, 3, 4, 5] + +y = [2, 3, 5, 7, 11] + +# Create a plot + +plt.plot(x, y) + +# Show the plot + +plt.show() + +``` + +This code will display a simple line plot of the given data. + +![Alt text](https://www.w3schools.com/python/img_matplotlib_plotting1.png "Introduction") + +### Customizing Plots + +#### Titles and Labels + +You can add titles and labels to your plots to make them more informative: + +```python + +plt.plot(x, y) + +# Adding title and labels + +plt.title('Sample Line Plot') + +plt.xlabel('X-axis Label') + +plt.ylabel('Y-axis Label') + +plt.show() + +``` + +#### Legends + +Legends help in identifying different plots on the same graph. Here's how to add them: + +```python + +# Sample data for two lines + +x = [1, 2, 3, 4, 5] + +y1 = [2, 3, 5, 7, 11] + +y2 = [1, 4, 6, 8, 10] + +# Plotting two lines + +plt.plot(x, y1, label='Prime Numbers') + +plt.plot(x, y2, label='Composite Numbers') + +# Adding legend + +plt.legend() + +plt.show() + +``` + +#### Colors and Styles + +You can customize the appearance of your plots with colors and line styles: + +```python + +# Different styles + +plt.plot(x, y1, color='blue', linestyle='-', marker='o', label='Prime') + +plt.plot(x, y2, color='red', linestyle='--', marker='x', label='Composite') + +plt.legend() + +plt.show() + +``` + +![Alt text](https://www.includehelp.com/python/images/line-plot.jpg "Introduction") + +### Types of Plots + +#### Line Plots + +Line plots are useful for showing trends over time or continuous data: + +```python + +plt.plot(x, y) + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_line_red.png) "Introduction") + +#### Scatter Plots + +Scatter plots are used to show the relationship between two sets of data: + +```python + +plt.scatter(x, y) + +plt.show() + +``` +![Alt text](https://www.w3schools.com/python/img_scatterplot.png "Introduction") + +#### Bar Plots + +Bar plots are great for categorical data comparison: + +```python + +categories = ['A', 'B', 'C', 'D', 'E'] + +values = [5, 7, 3, 8, 6] + +plt.bar(categories, values) + +plt.show() + +``` +![Alt text](https://www.w3schools.com/python/img_matplotlib_bars1.png "Introduction") + +#### Histograms + +Histograms are used to show the distribution of a dataset: + +```python + +import numpy as np + +data = np.random.randn(1000) + +plt.hist(data, bins=30) + +plt.show() + +``` +![Alt text](https://media.geeksforgeeks.org/wp-content/uploads/20231205223137/Screenshot-2023-12-05-222229.png "Introduction") + +#### Pie Charts + +Pie charts are useful for showing proportions: + +```python + +sizes = [15, 30, 45, 10] + +labels = ['A', 'B', 'C', 'D'] + +plt.pie(sizes, labels=labels, autopct='%1.1f%%') + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_pie_labels.png "Introduction") + +### Saving and Showing Plots + +You can save your plots to a file instead of showing them: + +```python + +plt.plot(x, y) + +plt.savefig('plot.png') + +plt.show()  # Optional, to display the plot + +``` + + +### Subplots + +Subplots allow you to create multiple plots in a single figure. This is useful for comparing different datasets or visualizing multiple dimensions of the same data. + +**Basic Subplot Creation:** + +```python + +import matplotlib.pyplot as plt + +# Create a figure and an array of subplots with 2 rows and 2 columns + +fig, axs = plt.subplots(2, 2) + +# Plot different types of plots in each subplot + +axs[0, 0].plot([1, 2, 3], [1, 4, 9])  # Line plot + +axs[0, 1].scatter([1, 2, 3], [1, 4, 9])  # Scatter plot + +axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3])  # Bar plot + +axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3)  # Histogram + +# Show the figure with subplots + +plt.show() + +``` + +![Alt text](https://www.w3schools.com/python/img_matplotlib_subplots1.png "Introduction") + +**Customizing Subplots:** + +You can adjust the layout and appearance of your subplots using various parameters. + +```python + +fig, axs = plt.subplots(2, 2, figsize=(10, 10), gridspec_kw={'width_ratios': [2, 1]}) + +# Adjust spacing between subplots + +fig.tight_layout(pad=3.0) + +axs[0, 0].plot([1, 2, 3], [1, 4, 9]) + +axs[0, 0].set_title('Line Plot') + +axs[0, 1].scatter([1, 2, 3], [1, 4, 9]) + +axs[0, 1].set_title('Scatter Plot') + +axs[1, 0].bar(['A', 'B', 'C'], [5, 7, 3]) + +axs[1, 0].set_title('Bar Plot') + +axs[1, 1].hist([1, 2, 2, 3, 3, 3, 4], bins=3) + +axs[1, 1].set_title('Histogram') + +plt.show() + +``` + +![Alt text](https://cdn.analyticsvidhya.com/wp-content/uploads/2024/02/example-3.png "Snapshot 3") + + +### Plotting with Pandas + +Pandas integrates seamlessly with Matplotlib, making it easier to create plots from DataFrames. Here's how you can leverage this integration. + +**Basic Pandas Plotting:** + +```python + +import pandas as pd + +# Create a DataFrame + +data = {'Category': ['A', 'B', 'C', 'D'], 'Values': [23, 45, 56, 78]} + +df = pd.DataFrame(data) + +# Plot a bar graph directly from the DataFrame + +df.plot(kind='bar', x='Category', y='Values', legend=False) + +plt.title('Bar Plot from DataFrame') + +plt.show() + +``` + +**Advanced Pandas Plotting:** + +You can create more complex plots and customize them further. + +```python + +# Create a DataFrame + +data = {'Category': ['A', 'B', 'C', 'D'], + +        'Values1': [23, 45, 56, 78], + +        'Values2': [22, 43, 55, 77]} + +df = pd.DataFrame(data) + +# Plot multiple columns + +df.plot(kind='bar', x='Category', y=['Values1', 'Values2']) + +plt.title('Multiple Columns Bar Plot') + +plt.xlabel('Category') + +plt.ylabel('Values') + +plt.legend(title='Legend') + +plt.show() + +``` + + + + +### Conclusion + +This comprehensive tutorial should give you a solid foundation in Matplotlib. You can further explore its extensive documentation and experiment with different types of plots and customizations to deepen your understanding. Happy plotting! From 368ab167bdbaaa5c4bca6074252c79a0d1c9662c Mon Sep 17 00:00:00 2001 From: ishaanv1206 <142810253+ishaanv1206@users.noreply.github.com> Date: Wed, 15 May 2024 19:19:52 +0530 Subject: [PATCH 9/9] Update index.md --- contrib/plotting-visualization/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/plotting-visualization/index.md b/contrib/plotting-visualization/index.md index 67bee6dc..7c32bc30 100644 --- a/contrib/plotting-visualization/index.md +++ b/contrib/plotting-visualization/index.md @@ -1,3 +1,4 @@ # List of sections - [Installing Matplotlib](matplotlib_installation.md) +- [Matplotlib Tutorial](Matplotlib_tutorial.md)