Python 3.3

Data Analyzer

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • String methods
  • Input function.
  • Conditionals

Learning goals:

  • Learn how to use the while-loop.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

One of the latest and most rapidly growing fields of science is Data Science. Data Science is an interdisciplinary field that uses programming and statistics to create insights into (big) data. With more and more data being readily available to scientists and companies, effective data science is becoming increasingly important for both scientific and commercial purposes. Social media businesses revolve around data science and essentially let their users “pay” with their data.

Python is a very useful programming language for data scientists. In this assignment, you will use Python to do some very basic data analysis. You will extract two of the most common characteristics of a list of integers: the maximum and the minimum.

For this task, you will use the python while-loop to repeatedly ask the user for integer input until the user writes any other non-integer input (e.g. “stop” or leave input empty). All the integers that the user inputs are the data set you will work with. Inside this loop, you will update the three characteristics of this list of integers in real time, that means you will do these things in the loop:

  • Ask for a new number;
  • Check if the number is numeric;
  • Check if the number is larger than the current maximum number;
  • Check if the number is smaller than the current minimum number;
  • If the number is not numeric: break out of the loop with the break keyword.

After finishing (because the user gave a non-integer input), your script should print the maximum and minimum in that order.

Write this in a script called `data_analyzer.py`. Use a string function to check if the input is integer. You do not have to implement any other input validation, as any incorrect input should result in the while-loop, and thus your script, finishing and providing the results. You may want to use the while-loop in combination with python’s `break` statement, which breaks out of the loop (read more here). Also, do not forget to cast the user’s input to integers (using `int()`) after checking that it actually is an integer.

Example usage:

-!- CODE language-bash -!-$ python3 data_analyzer.py
Input: 10
Input: 9
Input: 8
Input: 7
Input: 6
Input: 5
Input: 4
Input: 3
Input: 2
Input: 1
Input: stop
Maximum:  10
Minimum:  1

$ python3 data_analyzer.py
Input: 5
Input: 5
Input: stop
Maximum:  5
Minimum:  5

$ python3 data_analyzer.py
Input:
No integer given.

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.

With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.