Adapted from slides by Marty Stepp and Stuart Reges

Slides:



Advertisements
Similar presentations
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Advertisements

1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 4 Lecture 4-2: Strings reading: 3.3, self-check: Ch. 4 #12, 15 exercises:
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 4 Lecture 4-3: Strings, char reading: 3.3, self-check: Ch. 4 #12, 15 exercises:
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Cryptography.
If/else, return, user input, strings
Topic 6 loops, figures, constants Based on slides bu Marty Stepp and Stuart Reges from "Complexity has and will maintain.
Copyright 2010 by Pearson Education Building Java Programs Chapter 4 Lecture 4-3: Strings, char reading: 3.3, 4.3.
Intelligent Data Systems Lab. Department of Computer Science & Engineering Practices 컴퓨터의 개념 및 실습 4 월 11 일.
CSc 110, Autumn 2016 Lecture 15: lists Adapted from slides by Marty Stepp and Stuart Reges.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 4 Lecture 4-3: Strings, char reading: 3.3, self-check: Ch. 4 #12, 15 exercises:
Building Java Programs
Building Java Programs
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 15: Strings and Fencepost Loops
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
CSc 110, Autumn 2017 Lecture 16: Fencepost Loops and Review
CSc 110, Autumn 2017 Lecture 17: while Loops and Sentinel Loops
CSc 110, Spring 2017 Lecture 29: Sets and Dictionaries
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 27: Sets and Dictionaries
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs Chapter 4.3
Strings string: An object storing a sequence of text characters.
CSc 110, Spring 2017 Lecture 14: Boolean Logic and Midterm Review
FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.
CSc 110, Spring 2017 Lecture 28: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 5: The for Loop and user input
CSc 110, Spring 2018 Lecture 32: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 31: Dictionaries
CSc 110, Autumn 2017 Lecture 30: Sets and Dictionaries
CSc 110, Autumn 2016 Lecture 12: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
CSc 110, Spring 2017 Lecture 11: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
CS 106A, Lecture 9 Problem-Solving with Strings
CSc 110, Spring 2018 Lecture 33: Dictionaries
Adapted from slides by Marty Stepp, Stuart Reges & Allison Obourn.
CSc 110, Spring 2017 Lecture 5: Constants and Parameters
CSc 110, Spring 2018 Lecture 16: Fencepost Loops and while loops
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
CSc 110, Spring 2018 Lecture 17: while Loops and decomposition
Lecture 15: lists Adapted from slides by Marty Stepp and Stuart Reges
Lecture 22: lists Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 9: Graphics and Nested Loops
CSc 110, Autumn 2016 Lecture 5: Loop Figures and Constants
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2018 Lecture 14: Booleans and Strings
CSc 110, Spring 2017 Lecture 4: Nested Loops and Loop Figures
4.1 Strings ASCII & Processing Strings with the Functions
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2018 Lecture 7: input and Constants
CSc 110, Spring 2018 Lecture 5: The for Loop and user input
Building Java Programs
Lecture 19: lists Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
CSc 110, Spring 2018 Lecture 5: Loop Figures and Constants
Topic 6 loops, figures, constants
Building Java Programs
CSc 110, Spring 2018 Lecture 8: input and Parameters
CSc 110, Spring 2018 Lecture 10: More Graphics
functions: argument, return value
Using Objects (continued)
CSc 110, Autumn 2017 Lecture 8: More Graphics
Suggested self-checks: Section 7.11 #1-11
Strings string: An object storing a sequence of text characters.
Sequences Sequences are collections of data values that are ordered by position A string is a sequence of characters A list is a sequence of any Python.
Presentation transcript:

Adapted from slides by Marty Stepp and Stuart Reges CSc 110, Spring 2018 Lecture 15: Strings Adapted from slides by Marty Stepp and Stuart Reges

Name border Prompt the user for full name ALLISON LLISON LISON ISON SON ON N A AL ALL ALLI ALLIS ALLISO OBOURN BOURN OURN URN RN O OB OBO OBOU OBOUR Prompt the user for full name Draw out the pattern to the left This should be resizable. Size 1 is shown and size 2 would have the first name twice followed by last name twice

Other String operations - length Syntax: length = len(string) Example: s = "Merlin" count = len(s) # 6

Looping through a string The for loop through a string using range: major = "CSc" for letter in range(0, len(major)): print(major[letter]) You can also use a for loop to print or examine each character without range. for letter in major: print(letter) Output: C S c

String tests Method Description startswith(str) whether one contains other's characters at start endswith(str) whether one contains other's characters at end name = "Voldermort" if name.startswith("Vol"): print("He who must not be named") The in keyword can be used to test if a string contains another string. example: "er" in name # true

String question A Caesar cipher is a simple encryption where a message is encoded by shifting each letter by a given amount. e.g. with a shift of 3, A  D, H  K, X  A, and Z  C Write a program that reads a message from the user and performs a Caesar cipher on its letters: Your secret message: Brad thinks Angelina is cute Your secret key: 3 The encoded message: eudg wklqnv dqjholqd lv fxwh

Strings and ints All char values are assigned numbers internally by the computer, called ASCII values. Examples: 'A' is 65, 'B' is 66, ' ' is 32 'a' is 97, 'b' is 98, '*' is 42 One character long Strings and ints can be converted to each other ord('a') is 97, chr(103) is 'g' This is useful because you can do the following: chr(ord('a' + 2)) is 'c'