₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,163 members, 8,420,625 topics. Date: Friday, 05 June 2026 at 07:29 AM

Toggle theme

Simple Programming Codes - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingSimple Programming Codes (828 Views)

1 Reply (Go Down)

Simple Programming Codes by ABCthingx(op):
1. Reverse A String
python
#Reverse a String – Enter a string and the program will reverse it and print it out'
print ("____PROGRAM TO REVERSE A TEXT____ "wink
print('_____type bye to quit the program_____')
print ("____Write something then hit 'Enter'____"wink
text = '' #just a declaration
while text != "bye":
text = input()
x = len(text)
for i in text:
x -= 1
print(text[x], end='')
print()



 
C++

#include <iostream>
#include <string.h>
#include <string>
using namespace std;

Nairaland is shitty for codes
Honestly
I can't paste the c++ codes here

Re: Simple Programming Codes by airsaylongcome: 9:24pm On Jun 03, 2022
You have imported the std namespace so no need for std::cout again. cout, cin

You code isn't checking for edge cases such as when user just hits enter without any input. In a case like this your C++ code will output noitaralceD. I would initialize text with a blank string and check to ensure that user actually types an input.
Re: Simple Programming Codes by ABCthingx(op): 10:20pm On Jun 03, 2022
Re: Simple Programming Codes by ABCthingx(op):
airsaylongcome:
You have imported the std namespace so no need for std::cout again. cout, cin

You code isn't checking for edge cases such as when user just hits enter without any input. In a case like this your C++ code will output noitaralceD. I would initialize text with a blank string and check to ensure that user actually types an input.
Thanks i've modified
https://zerobin.net/?e396809972bf514e#tjf87uSWk7S0cTyGzhr72Qre1ofyLqb+sFpDJcoaGqk=

Re: Simple Programming Codes by airsaylongcome: 11:15pm On Jun 03, 2022
ABCthingx:
Thanks i've modified
https://zerobin.net/?e396809972bf514e#tjf87uSWk7S0cTyGzhr72Qre1ofyLqb+sFpDJcoaGqk=
Did you run the new code you entered? The if statement for "You must enter a text sir"

If you run it without entering text, that If just displays your prompt but does not stop the rest of the program from running
Re: Simple Programming Codes by Deicide: 9:08pm On Jun 04, 2022
Do not reinvent the wheel. Anyways write a programme that reverse ever word in the string.

So "He is a boy" becomes "eH so a yob"
Re: Simple Programming Codes by Emmyxclusive: 6:06am On Jun 07, 2022
ABCthingx:
1. Reverse A String
python
#Reverse a String – Enter a string and the program will reverse it and print it out'
print ("____PROGRAM TO REVERSE A TEXT____ "wink
print('_____type bye to quit the program_____')
print ("____Write something then hit 'Enter'____"wink
text = '' #just a declaration
while text != "bye":
text = input()
x = len(text)
for i in text:
x -= 1
print(text[x], end='')
print()



 
C++

#include <iostream>
#include <string.h>
#include <string>
using namespace std;

Nairaland is shitty for codes
Honestly
I can't paste the c++ codes here
in the python code what happens if a user enter a text in upper case or even combination of both? I think using the lower method on the text input is good
1 Reply

Can You Write Codes With A Tablet Instead Of A Laptop?Short Project: Arduino Uno Project (programming Codes)Need Help With My Codes.234

Sport Prediction APIHelpppppppppppp! Asp.net Code IssueHospital Management System Needed