Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help formatting my code, so my output looks like this. TXT FILE 12-30-2020 313 HellO! Bye235 11 Cdc What? Not now! Tues abba

I need help formatting my code, so my output looks like this.

image text in transcribed

TXT FILE

12-30-2020 313 HellO! Bye235 11 Cdc What? Not now! Tues abba HILLS 02-29-2019 78087 444-22-888 9878 7

MY CODE

import os

from datetime import datetime

#file name input

def readData():

all=[]

file=input('Enter file name with extension: ')

if os.path.isfile(file):

fobj = open (file , "r")

tmpStr = fobj.read()

Lines = file1.readlines()

for line in Lines:

all=line.strip(' ')

all.append(x)

else:

return []

#I found strptime online at programwiz and on the python glossary.

#I used it beacuse it creates a datetime from the string/file

def isValidDate(string):

try:

if string != datetime.strptime(string, "%m-%d-%Y").strftime('%m-%d-%Y'):

raise ValueError

return True

except ValueError:

return False

#Reverse to see if the string is eqaul or not.

def isPalindrome(string):

rev = reversed(string)

if list(string) == list(rev):

return True

return False

#Accepts a string and checks to see how many letters are uppercased

#If it has 1 the count will look for another.

def hasAtLeastTwoUppercase(string):

count=0

for i in string:

if (i.isupper()):

count=count+1

else:

pass

if count >=2:

return True

else:

return False

#int(i)%2!=0 is looking for odd digits and if count is greater then or eqaul

#to 2 it will give give both odd digits

def hasAtLeastTwoOddDigits(string):

count=0

for i in string:

if i.isnumeric():

if int(i)%2!=0:

count=count+1

else:

pass

if count >=2:

return True

else:

return False

#looking fo the last character in a string [-1:]

def endsWithS(string):

if string[-1:]=='s' or string[-1:]=='S' :

return True

else:

return False

def ending(string):

if isValidDate(string):

date.append(string)

if isPalindrome(string):

palin.append(string)

if hasAtLeastTwoUppercase(string):

upper.append(string)

if hasAtLeastTwoOddDigits(string):

odd.append(string)

if endsWithS(string):

ends.append(string)

date=[]

palin=[]

upper=[]

odd=[]

ends=[]

for i in all :

ending(i)

print("Valid Dates:", date)

print("Palindromes", palin)

print("At least TWO Uppercase", upper)

print("At least TWO odd digits", odd)

print("Ends with s or S", ends)

# I took what i did in lab 3 and brought it into here.

#I set it up to look for the vowels in the string

#and if found with 2 return them to a list

def countVowels(string):

vowels=['a','e','i','o','u','A','E','I','O','U']

string=string.lower()

count=0

for i in string:

if i in vowels:

count = count + 1

if count>=2:

return True

else:

return False

vow=[]

for i in all:

if countVowels(i):

vow.append(i)

print("Has TWO or more Vowels",vow)

Valid dates: ( 12-30-2020] Palindromes: ( 313, 11, Cdc, 232, abba, 78087, 7 ] At least TWO Uppercase: ( Hello!, What? Not now! Tues, HILLS ] At least TWO odd digits: [ 12-30-2020, 313, Bye235, 11, 02-29-2019, 78087,9878] Ends with sors: [ What? Not now! Tues, HILLS ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

What are the qualifications and experiences of your staff?

Answered: 1 week ago

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago