Page 252 - Robotics and AI class 10
P. 252

Python Programming                                                        #Coding & Computational Thinking


          1.  Create a list of all students in your class and sort them in alphabetical order.
          Ans.  # Create a list of students

              students = ['John', 'Shobit', 'Eva', 'Dinesh', 'Garima']
              # Sort the list in alphabetical order

              sorted_students = sorted(students)
              # Print the sorted list of students
              print("Sorted List of Students:")

              for student in sorted_students:
                  print(student,end=",")
              Output:

              Sorted List of Students:
              Dinesh,Eva,Garima,John,Shobit,
          2.  Find a word string of interest in a given sentence. For the same string match for exact case if a particular
              word string is present in a given sentence. Display output "String Name Found", or "String Name Not
              Found".

          Ans.  # Input sentence from the user

              sentence= input("Enter a sentence: ")
              # Target word string to search for
              word = input("Enter the word string to search for: ")

              # Check if the target string is present in the sentence
              if word in sentence:

                  print(word," is Found ")
              else:
                  print(word, "Not Found")
              Output:
              Enter a sentence: Have a nice day!

              Enter the word string to search for: nice
              nice is Found

          3.  Make a dictionary dataset of all cities in India and store their average temperature and pollution details.

          Ans.  # Create a dictionary dataset of cities in India
              cities = {

                  'Delhi': {'avg_temp': 28, 'pollution': 'High'},
                  'Mumbai': {'avg_temp': 32, 'pollution': 'Moderate'},
                  'Chennai': {'avg_temp': 30, 'pollution': 'Moderate'},

                  'Kolkata': {'avg_temp': 27, 'pollution': 'Moderate'}
                  }
              250     Touchpad Robotics & Artificial Intelligence-X
   247   248   249   250   251   252   253   254   255   256   257