Showing posts with the label User input programs

Featured Post

SQL Query: 3 Methods for Calculating Cumulative SUM

SQL provides various constructs for calculating cumulative sums, offering flexibility and efficiency in data analysis. In this article, we explore three distinct SQL queries that facilitate the computation of cumulative sums. Each query leverages different SQL constructs to achieve the desired outcome, catering to diverse analytical needs and preferences. Using Window Functions (e.g., PostgreSQL, SQL Server, Oracle) SELECT id, value, SUM(value) OVER (ORDER BY id) AS cumulative_sum  FROM your_table; This query uses the SUM() window function with the OVER clause to calculate the cumulative sum of the value column ordered by the id column. Using Subqueries (e.g., MySQL, SQLite): SELECT, t1.value, SUM(t2.value) AS cumulative_sum FROM your_table t1 JOIN your_table t2 ON >= GROUP BY, t1.value ORDER BY; This query uses a self-join to calculate the cumulative sum. It joins the table with itself, matching rows where the id in the first table is greater than or

2 User Input Python Sample Programs

Here are the Python programs that work on taking user input and giving responses to the user. These are also called interactive programs.  Python enables you to read user input from the command line via the input() function or the raw_input() function. Typically, you assign user input to a variable containing all characters that users enter from the keyboard. User input terminates when users press the <return> key (included with the input characters). #1 User input sample program The following program takes input and replies if the given input value is a string or number. my_input = input("Enter something: ")  try:       x = 0 + eval(my_input)       print('You entered the number:', my_input)  except:       print(userInput,'is a string') Output Enter something:  100 You entered the number: 100 ** Process exited - Return Code: 0 ** Press Enter to exit terminal.  #2 User input sample program The following program takes two inputs from the user and calcula