₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,130 members, 8,510,269 topics. Date: Friday, 30 October 2026 at 07:14 AM

Toggle theme

Simple Programming Codes - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Simple Programming Codes (891 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. • 2 • 3 • 4

Online Programming Vs College..? Which Is On Is Comfortable And Why?�� • How To Down Grade A Psp Of 4.05 Version • Cisco Opens Software Developer Contest