1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Artyom0805 [142]
3 years ago
9

Palindrome Checking - (hw5_part5.py) (8 points) Write a program that has two functions: check_palindrome will take a string argu

ment and return True if it is a palindrome, and False if not. Remember that a palindrome is a string which is the same forwards and backwards. Make sure to convert it all to lowercase with s.lower() because we'll count Racecar and rAcEcaR as palindromes. load_words which will take a file name argument and return a list of words. The words will all be on separate lines, but make sure to strip each line so that the '\n' character is removed.
Computers and Technology
1 answer:
baherus [9]3 years ago
5 0

Answer:

name = input("Enter the name of file: ")

f = open(name, "r")

for line in f.readlines():

  foundPalindrome = True

  line = line.strip()

  line = line.lower()

  i=0

  for j in range(len(line)-1,-1,-1):

      if i>= j:

          break

      if line[i] != line[j]:

          foundPalindrome = False

          break

      i+=1

  if foundPalindrome:

      print(line," is a Palindrome")

  else:

      print(line," is a not Palindrome")

Explanation:

  • Get the name of file from user and open it in read mode using the built-in open function.
  • Loop through the file to read the lines and set the boolean foundPalindrome to true.
  • Trim the string  and convert it to lower case alphabets.
  • Loop input from last to start  and break out of the loop if i is greater than or equal to j variable.
  • Set the boolean foundPalindrome to false if characters does not match.
  • Finally display that the word is a Palindrome if the boolean foundPalindrome is true otherwise display that word is not a Palindrome.
You might be interested in
We have said that the average number of comparisons need to find a target value in an n-element list using sequential search is
bija089 [108]

Answer:

Part a: If the list contains n elements (where n is odd) the middle term is at index (n-1)/2 and the number of comparisons are (n+1)/2.

Part b: If the list contains n elements (where n is even) the middle terms are  at index (n-2)/2 & n/2 and the number of comparisons are (n+2)/2.

Part c: The average number of comparisons for a list bearing n elements is 2n+3/4 comparisons.

Explanation:

Suppose the list is such that the starting index is 0.

Part a

If list has 15 elements, the middle item would be given at 7th index i.e.

there are 7 indices(0,1,2,3,4,5,6) below it and 7 indices(8,9,10,11,12,13,14) above it. It will have to run 8 comparisons  to find the middle term.

If list has 17 elements, the middle item would be given at 8th index i.e.

there are 8 indices(0,1,2,3,4,5,6,7) below it and 8 indices(9,10,11,12,13,14,15,16) above it.It will have to run 9 comparisons  to find the middle term.

If list has 21 elements, the middle item would be given at 10th index i.e.

there are 10 indices (0,1,2,3,4,5,6,7,8,9) below it and 10 indices (11,12,13,14,15,16,17,18,19,20) above it.It will have to run 11 comparisons  to find the middle term.

Now this indicates that if the list contains n elements (where n is odd) the middle term is at index (n-1)/2 and the number of comparisons are (n+1)/2.

Part b

If list has 16 elements, there are two middle terms as  one at would be at 7th index and the one at 8th index .There are 7 indices(0,1,2,3,4,5,6) below it and 7 indices(9,10,11,12,13,14,15) above it. It will have to run 9 comparisons  to find the middle terms.

If list has 18 elements, there are two middle terms as  one at would be at 8th index and the one at 9th index .There are 8 indices(0,1,2,3,4,5,6,7) below it and 8 indices(10,11,12,13,14,15,16,17) above it. It will have to run 10 comparisons  to find the middle terms.

If list has 20 elements, there are two middle terms as  one at would be at 9th index and the one at 10th index .There are 9 indices(0,1,2,3,4,5,6,7,8) below it and 9 indices(11,12,13,14,15,16,17,18,19) above it. It will have to run 11 comparisons  to find the middle terms.

Now this indicates that if the list contains n elements (where n is even) the middle terms are  at index (n-2)/2 & n/2 and the number of comparisons are (n+2)/2.

Part c

So the average number of comparisons is given as

((n+1)/2+(n+2)/2)/2=(2n+3)/4

So the average number of comparisons for a list bearing n elements is 2n+3/4 comparisons.

6 0
3 years ago
someone please do this for and send a screeshot or picture please its really important for my examsss :D​
dusya [7]

Answer:

I  dont know

Explanation:

i dont know

4 0
3 years ago
Which factors have increased the need for the latest cybersecurity technologies?
coldgirl [10]

The factors have increased the need for the latest cybersecurity technologies are A. smaller targets, C. customized threats.

<h3>What are the cybersecurity?</h3>

Cybersecurity is the safety of internet-related structures which include hardware, software program and records from cyber threats. The exercise is utilized by people and organizations to defend towards unauthorized get admission to to records facilities and different automated structures.

Cyberattacks can goal a huge variety of sufferers from character customers to organizations or maybe governments. When focused on groups or different organizations, the hacker's aim is normally to get admission to touchy and precious enterprise resources, which include highbrow property (IP), client records or price details.

Read more about the cybersecurity technologies:

brainly.com/question/26260220

#SPJ1

7 0
2 years ago
What two things can you track with adwords out of the box without making any code changes to your app?
charle [14.2K]

The question above has multiple choices as follows.

<span>a.       </span>You can actually track any custom event you want to define.

<span>b.      </span> All app installs and all in-app purchases

<span>c.       </span>Android app downloads and Android in-app purchases

<span>d.      </span>App installs and core user demographics

The correct answer is (C) Android app downloads and Android in-app purchases

 

You can automatically track android in-app purchases from Google play when someone who clicked your ad makes a purchase. There is no need of adding code to your app. The same concept works on Android app downloads.






3 0
3 years ago
Write an two<br>two paragraph about the importance of computer <br>​
muminat

Answer:

Increase your productivity. ...

Connects you to the Internet. ...

Can store vast amounts of information and reduce waste. ...

Helps sort, organize, and search through information. ...

Get a better understanding of data. ...

Keeps you connected. ...

Help you learn and keep you informed. ...

Can make you money.

4 0
4 years ago
Other questions:
  • I'll give brainlist to right answers
    7·1 answer
  • What is the command to use the memory diagnostics tool?
    11·1 answer
  • To make sure that you do not get too tired when typing for long periods, how often should you get up and stretch? Every 15 minut
    9·1 answer
  • How did mechanical clocks assist in completing work? How was work done previously?
    12·1 answer
  • You can display content variations to mobile, tablet or desktop users.
    12·1 answer
  • Before his job interview, Shabnam took the time to carefully wash and iron his best khaki pants and a button-down shirt. He even
    15·2 answers
  • The devices and methods that enable physically challenged computer uses to control their computer and provide input are referred
    15·1 answer
  • A new attack involves hacking into medical records and then offering these records for sale on the black market. A medical recor
    14·1 answer
  • Who are the following furries?
    10·2 answers
  • How does the sky change as onegets above Earth’s atmosphere?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!