Question

Given the following table: Key Student Number (0-99) 15 25 19 Value Grade (%) 57.8 92 74.3 a) Write code to initialize a list

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

grades = [(15,57.8),(25,92),(19,74.3)] #creating list of tuples from given table

#method 1 to append student 23 and grade 82

grades.append((23,82))   

#method 2 to insert student 23 and grade 82

grades.insert(len(grades),(23,82))

#method 1 to check student 33 is in grades

print("Student is present") if len([val for val in grades if val[0] == 33]) else print("Student is not present")

#method 2 to check student 33 is in grades

print("Student is present") if len([(st,gr) for st,gr in grades if st == 33]) else print("Student is not present")

#method 1 to check 55 is in grades

print("Grade is present") if len([val for val in grades if val[1] == 55]) else print("Grade is not present")

#method 2 to check 55 is in grades

print("Grade is present") if len([(st,gr) for st,gr in grades if gr == 55]) else print("Grade is not present")

Code and Output screenshots:

grades = [(15,57.8), (25,92), (19,74.3)] #creating list of tuples from given table #method i to append student 23 and grade 8

Student is present Student is present Grade is not present Grade is not present

Note: if you have any queries please post a comment before giving any review thanks a lot..always availale to help you..

Add a comment
Know the answer?
Add Answer to:
Given the following table: Key Student Number (0-99) 15 25 19 Value Grade (%) 57.8 92...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Student #2 C- 72% 144 34 0 40 70 Student #3 74% C 148 40 10 43 55 Student # 4 50 36 A 93% 186 10 90 Student #5 B+ 87% 1...

    Student #2 C- 72% 144 34 0 40 70 Student #3 74% C 148 40 10 43 55 Student # 4 50 36 A 93% 186 10 90 Student #5 B+ 87% 174 48 10 46 70 Student #6 56% 112 44 5 28 35 Student #7 65 84% 168 50 10 43 Student #8 48 B- 80% 159 46 10 55 Student #9 C+ 79% 158 50 10 73 25 Student #10 86% 172 33 5 44 90 Student...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • python program do not use dictionary, list only Complete the program found in assignment4.py. You may...

    python program do not use dictionary, list only Complete the program found in assignment4.py. You may not change any provided code. You may only complete the sections labeled: #YOUR CODE HERE Write a program that does the following. Reads the contents of Text from the include file, input.txt Create a dictionary of key-value pairs called index.txt Key: This represents the individual word Value: This is a list of the line number from Text where Key appeared Example: If the word...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development p...

    Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development practices and problem solving strategies: a) Start by writing the documentation for the function. Use docstrings shown in lecture and lab. b) Write test calls to the function in your main function for the different cases of input the function will encounter. This will help you understand the behavior of the function and later behave as tests for your function. c) Define the function d)...

  • Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data...

    Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...

  • Declare and initialize 4 Constants for the course category weights: The weight of Homework will be...

    Declare and initialize 4 Constants for the course category weights: The weight of Homework will be 15% The weight of Tests will be 35% The weight of the Mid term will be 20% The weight of the Fin al will be 30% Remember to name your Constants according to Java standards. Declare a variable to store the input for the number of homework scores and use a Scanner method to read the value from the Console. Declare two variables: one...

  • Write the C program, to achieve as shown in the sample code execution, using the given...

    Write the C program, to achieve as shown in the sample code execution, using the given struct and using the comments in the given main program below: typedef struct{ char first[20]; char last[20]; float gpa; int score; } student; int main(void){ student *ptr; //first name //last name //student gpa //student score } //ask a user to enter the number of students, num //dynamically allocate memory for an array of students of the appropriate size (i.e. //num that the user just...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT