Python help

lemonhead71

Junior Member
Oct 31, 2012
8
0
0
I been looking over these two problems forever now and I still don't know how to solve them. Please help me, I need sleep. Thank you.



1. Write a program the accepts a sentence as input and converts each word to upper case "Pig Latin". In one version, to convert a word to Pig Latin you remove the first letter and place that letter at the end of the word. Then you append the string "ay" to the word. Here is an example:

English: I slept most of the night

Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

Write functions and provide testing as per usual.

2.A 13 digit ISBN (International Standard Book Number) consists of the groups of characters:
A prefix of 978 or 979
the group identifier
the publisher code
the item number
a single check digit

Groups b, c, and d have a minimum length of 1, but may be longer. The groups of digits are separated by hyphens. Thus,

978-3-16-148410-0

is a valid ISBN number.

Write a Python function valid_isbn that takes a string as a parameter and returns True if the string is a valid ISBN, and False otherwise.
 

Dratickon

Junior Member
May 13, 2012
21
0
0
These types of "do my homework" questions are typically frowned upon. What parts are you having difficulty with? What don't you understand? What have you tried? It's easy enough to just give you the answers, but I'd imagine that the concepts covered by these problems are pretty important for anything you'll be doing as you move forward in the class.
 

lemonhead71

Junior Member
Oct 31, 2012
8
0
0
Thanks for replying. My problem relates to both questions which is I'm having trouble targeting specific sections of a string. For example, in question 1 it asks you must remove the first letter and place that letter at the end of the word. My question is how do you when a new word starts or ends in a string. I know how to target specific characters in a string but I won't know what the user types as a sentence so I also wouldn't know what character sequence makes one word. As for question 2 it says b, c, and d have a minimum length of 1 so I'm not sure how I would account for that when I make a new string with all of the 13 digit ISBN requirements.
 

Chris27

Member
Sep 19, 2005
140
0
0
I also wouldn't know what character sequence makes one word.

Well, if you treat white space as your delimiter, a word would simply be a continuous sequence of non white space characters. If you want a simple solution, a python string should have some sort of split() function that will return an array of all of the words in the string. You could then translate each word in the array to Pig Latin and join them to derive your final string.
 

lemonhead71

Junior Member
Oct 31, 2012
8
0
0
Thanks I made some progress but I'm stuck again when i got this error: word1 = b[1:]+b[:1]+'AY'
TypeError: can only concatenate list (not "str") to list

My code:
stringg=input('English:').strip()
b=stringg.split()
word1 = b[1:]+b[:1]+'AY'
word2=word1.upper()
print(word2)

for c in word2:

print('{0}'.format(c))

My teacher didn't cover for loops and strings that well, so please be basic in your explanation.
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
In 2), the teacher probably expects you to split the ISBN string using hyphen as the delimiter, check if you got the correct amount of parts from the split, then inspect the individual parts for whether they are numbers, and finally whether they are the correct kind of numbers.

That said, the problem is practically tailor made to be solved using a regular expression, and that is what I would personally use. Takes a decent amount of learning if you haven't encountered them before, though.
http://docs.python.org/2/library/re.html
 

Dratickon

Junior Member
May 13, 2012
21
0
0
Thanks I made some progress but I'm stuck again when i got this error: word1 = b[1:]+b[:1]+'AY'
TypeError: can only concatenate list (not "str") to list

My code:
stringg=input('English:').strip()
b=stringg.split()
word1 = b[1:]+b[:1]+'AY'
word2=word1.upper()
print(word2)

for c in word2:

print('{0}'.format(c))

My teacher didn't cover for loops and strings that well, so please be basic in your explanation.

You're on the right track, but you're looping in the wrong spot/over the wrong variable. Hint: What does your 'b' variable represent?

Code:
[spoiler]
englishSentence = raw_input('English: ').strip()
englishSentenceAsArray = englishSentence .split()
pigLatinSentence = 'Pig Latin: '
for word in englishSentenceAsArray :
    wordAsPigLatin = word[1:] + word[0] + 'AY '
    pigLatinSentence += wordAsPigLatin.upper()
print pigLatinSentence
[/SPOILER]

In 2), the teacher probably expects you to split the ISBN string using hyphen as the delimiter, check if you got the correct amount of parts from the split, then inspect the individual parts for whether they are numbers, and finally whether they are the correct kind of numbers.

That said, the problem is practically tailor made to be solved using a regular expression, and that is what I would personally use. Takes a decent amount of learning if you haven't encountered them before, though.
http://docs.python.org/2/library/re.html

Using a regular expression was my first thought as well. To the original author, have you tried splitting based on the hyphen as suggested? If so, how did that go?
 
Last edited:
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |