CS 116 Tutorial 6 Strings, Raw Input, Lists. 1. Write a function convert_format that consumes nothing, but takes keyboard input. The program prompts "Enter.

Slides:



Advertisements
Similar presentations
Probability and Conditional Probability. Probability Four balls What is the probability of choosing the ball in the red box? Since there are four balls.
Advertisements

Modelling & Datatypes John Hughes. Software Software = Programs + Data.
Combinations Examples
Report Card P Only 4 files are exported in SAMS, but there are at least 7 tables could be exported in WebSAMS. Report Card P contains 4 functions: Extract,
Please Sit... You do not need materials at this time.
Lecture 18 Dr. MUMTAZ AHMED MTH 161: Introduction To Statistics.
1 Chapter 3 Input Devices. 2 Overview of the Input Process.
Probability: Mutually Exclusive Events 1. There are 3 red, 4 black and 5 blue cubes in a bag. A cube is selected at random. What is the probability of.
Creating Tables Unit 9 - Databases.
Modelling & Datatypes Koen Lindström Claessen. Software Software = Programs + Data.
Counting. Counting in Algorithms How many comparisons are needed to sort n numbers? How many steps to compute the GCD of two numbers ? How many steps.
Module 4: Statements and Exceptions. Overview Introduction to Statements Using Selection Statements Using Iteration Statements Using Jump Statements Handling.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
15.7 Probability Day 3. There are 2 nickels, 3 dimes, and 5 quarters 1.) Find the probability of selecting 1 nickel, 1 dime, and 1 quarter in that order.
Your First Discard In Bridge, there are only two legal ways to communicate with your partner:- 1. The bids you make, and 2. The cards you play. Here we.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Whiteboardmaths.com © 2004 All rights reserved
Counting Techniques 1. Sequential Counting Principle Section
Index Student Activity 1: Questions to familiarise students with the
CSCI3170 Introduction to Database Systems
Copyright © Cengage Learning. All rights reserved.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Refreshing Your Skills for Chapter 10.  If you flip a coin, the probability that it lands with heads up is 1/2.  If you roll a standard die, the probability.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
PROBABILITY. FACTORIALS, PERMUTATIONS AND COMBINATIONS.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Copyright 2013, 2010, 2007, Pearson, Education, Inc. Section 12.2 Theoretical Probability
Chapter 10: Counting Methods
PROBABILITY The language of probability 01½ Impossible Very unlikely Unlikely Even chance Likely Almost certain Certain The probability of an event is.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
MATH 110 Sec 13.1 Intro to Probability Practice Exercises We are flipping 3 coins and the outcomes are represented by a string of H’s and T’s (HTH, etc.).
Draw 3 cards without replacement from a standard 52 card deck. What is the probability that: 1.They are all red ? 2.At least one is black ? 3.They are.
Do Now. Introduction to Probability Objective: find the probability of an event Homework: Probability Worksheet.
CS Lecture 11 To Exclude Or Not To Exclude? + -
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
Lesson Objective: Understand how to make and use Algorithms Learning Outcome: Design your own algorithms and flowcharts. Algorithms and Flowcharts.
PROBABILITY What is the probability of flipping a head? There is a 1 in 2 chance – ½ = 0.5.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
Texas State Technical College DISCOVER! Conversion Functions “Convert this!”
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Chapter 9 - Formatted Input/Output
Counting by Complement and the Inclusion/Exclusion Principle
Discrete Structures for Computer Science
Section 16 Inclusion/Exclusion
Random Sampling Playing cards are our participants
Probability Part 2.
The Addition Rule.
Unit 4 – Combinatorics and Probability Section 4
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Mathematics for Computer Science MIT 6.042J/18.062J
sscanf()- string scan function
Chapter 9 - Formatted Input/Output
Strong’s GMAS Review, Week 5, Problems 4 - 5
Combination and Permutations Quiz!
TUTORIAL 8 CS 137 F18 November 5th.
Probability Section 19 NOTE: We are skipping Section 18. 2/21/2019
HTML5 Form Types – Newer Available Fields
Section 12.2 Theoretical Probability
Section 6.4 Counting and Combinations with Multiple Cases
ICT Database Lesson 2 Designing a Database.
Section 12.2 Theoretical Probability
Hamlet: Lit. Analysis card Game
Homework Due Friday.
321 Section Feb. 21 Natalie Linnell.
Section 12.2 Theoretical Probability
Presentation transcript:

CS 116 Tutorial 6 Strings, Raw Input, Lists

1. Write a function convert_format that consumes nothing, but takes keyboard input. The program prompts "Enter date: ". The inputted string is of the form "dd/mm/yyyy" corresponding to a valid date, where dd is a 1-2 digit number (between 1 and 31, depending on the month), mm is a 1-2 digit number (between 1 and 12), and yyyy is a 1-4 digit integer. The function produces a string of the form "Month dd, yyyy". For example, convert_format() Enter date: 12/10/2012 => "October 12, 2012" convert_format() Enter date: 11/1/1999 => "January 11, 1999" Use string methods and string formatting (using %) to complete this question.

A card is a list of length 2 where -the first item is an integer between 1 and 10, inclusive, representing the value of the card, and -the second item is a string ("hearts", "spades", "clubs", or "diamonds") representing the suit of the card.

2. Write a function create_cards that consumes a list of card values (integers between 1 and 10) and a list of suit values (one of the four suit strings), and produces a list of cards created pair- wise from the consumed lists. For example, create_cards([4,1,10],["hearts","diamonds","clubs"]) => [[4,"hearts"], [1, "diamonds"], [10, "clubs”]]

3. Write a function choose_by_colour that consumes a list of cards ( hand ) and a string "red" or "black" ( colour ) and produces a list of the values of the cards in hand of the appropriate colour (spades and clubs are "black", hearts and diamonds are "red"). For example, choose_by_colour([[1,'hearts'], [9, 'spades'], [3,'diamonds']], 'red') => [1,3]

4. Write a function modify_list that consumes a list of integers (called numbers ) and a single integer ( n ). The function produces None, but mutates the list in the following way: - If n does not appear in numbers then add it to the end of numbers. - If n appears once, remove n from numbers. - If n appears at least twice, remove the first and last occurences of n.

5. Write a function flip_colour that reads in a card and mutates the suit of that card to a different colour: if the card read in is a heart, it is mutated to a spade (and vice versa), while if the card read in is a club, it is mutated to a diamond (and vice versa). Then write a function flip_hand that reads in a list of cards (a hand), and mutates the suit of each card in the list so that its colour is flipped in this way.

6. Write a function sanitize that consumes a string and produces a similar string but with any non- alphanumeric characters removed. For example, => "Test"