Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Data Analytics Using Python/Lab1 Python Basics.ipynb
3074 views
Kernel: Python 3 (ipykernel)

Question 1: Student Grade Calculator

Write a Python script that:

  • Takes student names and their marks (out of 100) as input from the user in a loop (until the user types "stop").

  • Stores this information in a dictionary where the key is the student name and the value is the marks.

  • After input is complete, iterate through the dictionary and:

  • Print each student's name with their grade based on the following rules:

    90-100: Grade A 75-89: Grade B 50-74: Grade C Below 50: Grade F
# Student Grade Calculator # Initialize an empty dictionary students = {} while True: name = input("Enter student name (or 'stop' to finish): ") if name.lower() == 'stop': break marks = int(input(f"Enter marks for {name}: ")) students[name] = marks print("\nGrades:") for student, marks in students.items(): if marks >= 90: grade = 'A' elif marks >= 75: grade = 'B' elif marks >= 50: grade = 'C' else: grade = 'F' print(f"{student}: {grade}")
Enter student name (or 'stop' to finish): Ojes Enter marks for Ojes: 90 Enter student name (or 'stop' to finish): Ashi Enter marks for Ashi: 100 Enter student name (or 'stop' to finish): 50 Enter marks for 50: 50 Enter student name (or 'stop' to finish): stop Grades: Ojes: A Ashi: A 50: C

Question 2: Word Frequency Counter

Write a Python script that:

  • Takes a sentence as input from the user.

  • Splits the sentence into words and counts the frequency of each word using a dictionary.

  • Print the frequency of each word, and also:

  • If a word appears more than 3 times, print "High Frequency" next to it.

  • Otherwise, print "Normal Frequency"

# Word Frequency Counter sentence = input("Enter a sentence: ") words = sentence.split() # Initialize an empty dictionary for word count word_count = {} # Count frequency of each word for word in words: word = word.lower() # Convert to lowercase for consistency if word in word_count: word_count[word] += 1 else: word_count[word] = 1 # Display results print("\nWord Frequencies:") for word, count in word_count.items(): if count > 3: status = "High Frequency" else: status = "Normal Frequency" print(f"{word}: {count} -> {status}")
Enter a sentence: happy happy sad sad Word Frequencies: happy: 2 -> Normal Frequency sad: 2 -> Normal Frequency