Python exercise

Pagina: 1
Acties:
  • 1.393 views

Onderwerpen

Vraag


Acties:
  • 0 Henk 'm!

  • julesvdv
  • Registratie: Augustus 2022
  • Laatst online: 29-08-2022
Hello guys
a dificult exercise i dont find it.
A palindrome sentence is a sentence that forms a palindrome when only the letters of the sentence are taken into account. Thus, all characters in the sentence that are not letters (e.g., spaces and punctuation marks) are ignored. In addition, no distinction is made between upper and lower case letters either. Examples of palindromic sentences are "There is still treachery there, Sire." and "A man, a plan, a canal: Panama!".

Input
The first line of input contains a natural number that indicates how many test cases there are. The next lines of input each contain a sentence.

Output
For each of the sentences in the input, write out whether they are palindrome sentences (palindrome sentence) or not (no palindrome sentence).

Beste antwoord (via julesvdv op 29-08-2022 11:24)


  • PageFault
  • Registratie: April 2002
  • Laatst online: 10-09 19:15
What sentence did you enter and what gave the output of the program?

Could you please mark-up the code as idention is very important for Python. Please see the forum help how to do that.

Alle reacties


Acties:
  • +1 Henk 'm!

  • PageFault
  • Registratie: April 2002
  • Laatst online: 10-09 19:15
What code did you come up yourself?

It should be easy: input the string, reverse the string https://www.w3schools.com..._howto_reverse_string.asp in a different variable and compare it with the original string. When they match, it is a palindrome.

Just forgot, sorry: first make all characters either upper or lowercase, for example with https://www.geeksforgeeks.org/python-string-lower/

And remove all non-letters from the string afterwards before reversing and comparing the strings.

[ Voor 31% gewijzigd door PageFault op 29-08-2022 11:12 ]


Acties:
  • 0 Henk 'm!

  • julesvdv
  • Registratie: Augustus 2022
  • Laatst online: 29-08-2022
palin = int(input("Geef een getal: "))
palindroom = int(input("Geef een zin: ")
for i in range(palin):
palind = palindroom.reverse()
if palindroom != palind:
print("geen palindroomzin")
else:
print("palindroomzin")
this is what i got but doont know ho to proceed

Acties:
  • Beste antwoord
  • +1 Henk 'm!

  • PageFault
  • Registratie: April 2002
  • Laatst online: 10-09 19:15
What sentence did you enter and what gave the output of the program?

Could you please mark-up the code as idention is very important for Python. Please see the forum help how to do that.

Acties:
  • 0 Henk 'm!

  • julesvdv
  • Registratie: Augustus 2022
  • Laatst online: 29-08-2022
Leon sees Noel.
and number 1
then its says not a palindroomzin but it is indeed one

Acties:
  • 0 Henk 'm!

  • PageFault
  • Registratie: April 2002
  • Laatst online: 10-09 19:15
julesvdv schreef op maandag 29 augustus 2022 @ 11:24:
Leon sees Noel.
and number 1
then its says not a palindroomzin but it is indeed one
For a test: enter the sentence without capital letters and without the dot, so:

leon sees noel

what happens then?

Acties:
  • +1 Henk 'm!

  • DataGhost
  • Registratie: Augustus 2003
  • Laatst online: 14-09 13:27

DataGhost

iPL dev

Mag hier gewoon in het Nederlands. Je slaat een aantal stappen over die in de probleemomschrijving staan. Print eens de variabelen palind en palindroom onder elkaar en kijk of ze vindt dat die er hetzelfde uitzien. Dan snap je ook waarom je de uitvoer "geen palindroomzin" krijgt.

Acties:
  • 0 Henk 'm!

  • julesvdv
  • Registratie: Augustus 2022
  • Laatst online: 29-08-2022
If i print noel sees leon then answer is palindroom but with Leon sees noel its false

Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
Die vragen die er staan wanneer je hier een nieuw topic opent staan er niet voor niets ;)
Mijn vraag
...

Relevante software en hardware die ik gebruik
...

Wat ik al gevonden of geprobeerd heb
...
We kunnen/willen je best helpen, maar daarvoor verwachten we (heel wat meer) eigen inzet van jezelf. Zie onze Quickstart. Verder: wanneer je code post, gebruik dan code tags aub.

Tot slot: we spreken hier gewoon Nederlands ;)

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij

Pagina: 1

Dit topic is gesloten.