Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,798 members, 7,817,305 topics. Date: Saturday, 04 May 2024 at 09:54 AM

Simple Programming Codes - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Simple Programming Codes (577 Views)

Short Project: Arduino Uno Project (programming Codes) / Review My Programming Language - SIMPLE PROGRAMMING Language / Simple Programming Assignment. (2) (3) (4)

(1) (Reply) (Go Down)

Simple Programming Codes by ABCthingx: 8:22pm On Jun 03, 2022
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.

1 Like

Re: Simple Programming Codes by ABCthingx: 10:20pm On Jun 03, 2022
Re: Simple Programming Codes by ABCthingx: 10:24pm On Jun 03, 2022
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)

Machine Learning. / Deleted*** / Web Training Starting Tomorrow �

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.