Categories
Python

Count Number of Words From a Text File in Python

 In this program I will show you how to count the number of words from a text file using Python programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

Program Listing

data.txt

Python Programming is Fun and Profit
Professor Jake Rodriguez Pomperada


reading_textfile.py

# reading_textfile.py
# Mr. Jake Rodriguez Pomperada, MAED-IT, MIT
# www.jakerpomperada.com www.jakerpomperada.blogspot.com
# jakerpomperada@gmail.com
# April 3, 2021
# Bacolod City, Negros Occidental

print()
print("\tCount Number of Words From a Text File in Python");
print()
try:
    print()
    fr = open("data.txt","r")
    for line in fr:
        line = line.strip("\n")
        print(line.upper())
        words = line.split()

        print()
        print('Total number of words: ', len(words))
        print("-----------------------------------------------")
        print()
        print("\tEND OF PROGRAM");
        print()
    fr.close()
except FileNotFoundError:
    print("File is not found")
Categories
Python

Paper,Scissors, and Rocks Game in Python

 A simple program paper,scissors, and rocks game that I wrote using Python programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

Program Listing

# Mr. Jake Rodriguez Pomperada, MAED-IT, MIT
# www.jakerpomperada.com www.jakerpomperada.blogspot.com
# jakerpomperada@gmail.com
# February 23, 2021
# Bacolod City, Negros Occidental

print()
print("\tPaper,Scissors, and Rocks Game in Python");
print()
p1 = str(input("Player1: "))
p2 = str(input("Player2: "))

if (p1.lower()  =='p') and (p2.lower() =='r'):
    print("Player 1 wins! Paper covers rock!")
elif (p2.lower() == 'p') and (p1.lower() == 'r'):
    print("Player 2 wins! Paper covers rock!")

elif  (p1.lower() == 's') and (p2.lower() == 'p'):
    print("Player 1 wins! Scissors cuts paper!")
elif (p2.lower() == 's') and (p1.lower() == 'p'):
    print("Player 2 wins! Scissors cuts paper!")

elif (p1.lower()=='r') and (p2.lower()=='s'):
    print("Player 1 wins!. Rock breaks scissors")
elif (p2.lower()=='r') and (p1.lower()=='s'):
    print("Player 2 wins!. Rock breaks scissors")

elif (p1.lower()=='p') and ( p2.lower()=='p'):
    print("Draw!")
elif (p1.lower()=='r') and (p2.lower()=='r'):
    print("Draw!")
elif (p1.lower() == 's') and (p2.lower() == 's'):
    print("Draw!")

else:
    if (p1.lower()!= 'p' or p1.lower() !='r'  or p1.lower()!='s') \
       and ( p2.lower()=='p'  or p2.lower() == 'r' or p2.lower()=='s'):
          print(f"Player 1 entered an invalid value \"{p1}\" ")
    elif (p2.lower()!= 'p'  or p2.lower()!='r'  or p2.lower() !='s') \
       and (p1.lower()=='p' or p1.lower() == 'r' or p1.lower() =='s'):
          print(f"Player 2 entered an invalid value \"{p2}\" ")
    else:
        print(f"Player 1 entered an invalid value \"{p1}\" ")
        print(f"Player 2 entered an invalid value \"{p2}\" ")

print()
print("\tEND OF PROGRAM");
print()