Quiz 5

Para la primera parte de este ejercicio primero le pregunte una oración o palabra al usuario en caso de que sea una oración antes de verificar si es o no un palindromo, le quito los espacios quedando asi:

Anita lava la tina ———–Anitalavalatina

Después convierto toda la palabra en minúsculas, para poder depues voltearla y verificar si es un palindromo o no.

palabras=str(input("Escribe una palabra u oracion: "))
def is_palindrome (a):
minisculas=a.lower().replace(' ', '')
s=""
palindromo=str(minisculas)[::-1]
if minisculas==palindromo:
res=print("La palabra u oracion: ",a,"es un palindromo")
else:
res=print("La palabra u oracion: ",a,"no es un palindromo")
return s
print(is_palindrome(palabras))

Codigo en github:

Compilado:

Para la segunda parte le pregunte al usuario cuantos números quería ingresar a una lista, despues declare 2 listas una para los números que ingrese el usuario y la otra para los numero que sean divisibles entre 3 e implemente dos ciclos un “while” para ingresar los números que el usuario digite en la primera lista y un “for” para analizar uno por uno los numero que el usuario ingreso, al ser divisibles entre 3 se agregan a la segunda lista y solo se sumaran los que sean divisibles entre 3.

Codigo:

      

def find_threes():
con=0
suma=0
nada=""
n=int(input("Cuantos numeros desa ingresar:"))
lista=list()
lista3=list()
while n>con:
r=int(input("Ingresa los numeros por favor: "))
lista.append(r)
con=con+1
for z in lista:
if (z%3==0):
suma=z+suma
lista3.append(z)
print("Estos son los numero que ingresaste",lista,"de los cuales estos son divisibles entre 3 ",lista3," y la suma de estos numeros es: ",suma)
return nada
print(find_threes())



Codigo en github:

Compilado:

quiz5

#include <iostream>
using namespace std;
bool palindrome(string word){
int c=1;
string invert=string(word.rbegin(), word.rend());
int z=word.size();
for(int i=0; i<z; i=i+1){
if (word[i]==invert[i]) {
return true; }
else {
return false; }
return 0; } }
int main(){
string word;
cout<<“This program calculate if a single word is a palondrome or not”;
cout<<“Give the word to prove if its a palindrome or not”<<endl;
cin>>word;
if(palindrome(word)==false) {
cout<<word<<” “<<“Its NOT palindrome”<<endl; }
else{
cout<<word<<” “<<“It´s a Palindrome”<<endl; }
return 0;
}

CÓDIGO 2.

#include <iostream>
using namespace std;

int threesAdd(int range[], int numOfNum) {
int total=0;
int divi=0;
int val;
for(int i=0; i<numOfNum; i=i+1){
val=range[i];
if(val%3==0){
cout<<val<<” “<<“Is divisible so it goes to the addition”<<endl;
divi=divi+1;
total=total+val;}
else { } }
cout<<“The total divisble numbers:”<<” “<<divi<<” “;
return total; }

int main() {
int values;
cout<<“This program evaluates a range of numbers and make a total addition”<<endl;
cout<<“But it only add the ones which are divisibles by 3″<<endl;
cout<<“How many values you will type?”<<” “;
cin>>values;
int range[values];
for(int i=0; i<values; i=i+1){
cout<<“Type the”<<” “<<i+1<<” “<<“number”<<endl;
cin>>range[i]; }
cout<<“The total addition of the no.3 divisibles is:”<<” “<<threesAdd(range, values)<<endl;
return 0;
}

Quiz #5

El quiz 5 consiste en 2 programas, el primero se trata de palindromos, y el segundo te permite sumar números divisibles entre 3.

1111

Programa 1 – Palindromos

¿Qué son los palindromos?

  • Los palindromos son palabras o frases que se escriben / leen de igual forma al derecho y al revés; aquí unos ejemplos de palindromos:
  • anita lava la tina
  • reconocer
  • ana
  • la ruta natural

Este programa no acepta los espacios, por lo tanto, si se quiere escribir un palindromo compuesto por varias palabras, se tienen que escribir sin espacio.

El usuario teclea algo, si lo tecleado es un palindromo, el programa te afirmará que si es un palindromo, si lo tecleado no es un palindromo, el programa te dará a conocer que o que estás escribiendo no es un palindromo.

Esta operación es principal del programa, ya que hace que el programa pueda leer al revés:

Quiz 5 ejercicio 1 (función)

Aquí el código completo junto con su compilación:

Quiz 5 ejercicio 1

Link GitHub: Quiz #5 Prog 1

Programa 2 – Suma de números divisibles entre 3

El programa te pregunta por diferentes números los cuales se van agregando a la lista, y como dice el título, únicamente se van a sumar los números que sean divisibles entre 3, los otros números son ignorados.

Para este programa se utilizaron vectores y el loop while

A continuación se muestra el código completo en un screenshot y su respectivo link en GitHub.

Quiz 5 ejercicio 2

Link GitHub: Quiz #5 Prog 2

#Quiz05

Hola a todos, el dia de hoy les traigo nuevo codigo, basicamente son 2 pequeños programas el primero determina si una palabra dada por el usuario es un palindromo y el segundo hace la suma de todos los numeros divisibles entre 3 dados por el usuario.

Como de costumbre tuve problemas para realizar los programas, pero gracias a que me tope con un blog bastante  bueno de una compañera de clases, pude basarme en su estrucutra y sacar mi codigo adelante.

Por cierto para los que se estan preguntando…  Un palíndromo es una palabra, número o frase que se lee igual hacia adelante que hacia atrás. Si se trata de un número, se llama capicu Habitualmente, las frases palindrómicas se resienten en su significado cuanto más largas son.

Haga click para ver el pase de diapositivas.

Links de ayuda:

https://julesmdblog.wordpress.com/

https://es.wikipedia.org/wiki/Pal%C3%ADndromo

Codigo:

https://github.com/OscarBaez/My-codes/blob/master/Quiz5.cpp

https://github.com/OscarBaez/My-codes/blob/master/Quizb.cpp

 

quiz 5

  • Create a function called is_palindrome which receives a string as a parameter and returns true if that string is a palindrome, false otherwise. Remember that a palindrome is a word that is the same forward or backward. For full points your function must ignore case and must work with any character (not just letters). So (“Dad$dad” is a palindrome even though the D is capital and d is lower

en este programa se ´pide al usuario una palabra  que no contenga espacios y cuando la lee el programa por medio de la función backwards va comparando la primera letra de la palabra con la ultima y asi sucesivamente con un ciclo for para indicarle al programa en que posición de la letra se quiere comparar, hasta llegar hacer un condicional if/else de que si las letras al revés son las mismas que al derecho, debe de mostrar en pantalla que la palabra insertada es un palíndromo

code github part 1

Captura de pantalla 2016-04-08 00.06.00

  •  Create a function called find_threes that receives as a parameter a list (or Vector or array for C++ students) of numbers and returns the sum of all numbers in that list that are evenly divisible by 3. Note if using vectors, you will need an additional parameter to represent the number of numbers in the array. So if the list was [0,4,2,6,9,8,3,12], the function would return 30 (0+6+9+3+12)

es este segundo programa se trata de que por medio de un vector el usuario va a indicar que tata cantidad de numeros queire insertar y una vez que lo inserte, entonces por medio de un ciclo for va a pedirle los numeros que quiere guardar en cada contador del vector. asi pues mientras se estan insertando los numeros se inserta tambien un condicional if/else para que desde ese momento el numero que el usuario este

Captura de pantalla 2016-04-08 00.07.08

Continue reading “quiz 5”

Quiz 5

These are the instructions:

  1. Create a function called is_palindrome which receives a string as a parameter and returns true if that string is a palindrome, false otherwise. Remember that a palindrome is a word that is the same forward or backward. For full points your function must ignore case and must work with any character (not just letters). So (“Dad$dad” is a palindrome even though the D is capital and d is lower case).

Captura de pantalla 2016-04-07 a las 14.56.49

In this code, you will need strings, and arrays and also the for loop.
You’ll need to add this library #include <string>

Now to know if it the word is a palindrome, the code must be like this:
int large = word.length();
for (int x = large – 1; x >= 0; x–){
backwards += word[x];
}

the word.length() returns the length of the string, in terms of bytes. So for the “For” loop the loop will be adding the last letter to the first of the word, one by one, and save it in “backwards”. And if the word and backwards are the same, then that is a palindrome.

You can take a look on this web page. http://www.cplusplus.com/reference/string/string/length/

And the Code in GitHub

  1. Create a function called find_threes that receives as a parameter a list (or Vector or array for C++ students) of numbers and returns the sum of all numbers in that list that are evenly divisible by 3. Note if using vectors, you will need an additional parameter to represent the number of numbers in the array. So if the list was [0,4,2,6,9,8,3,12], the function would return 30 (0+6+9+3+12).

 

In this one, the code must look something like this: Captura de pantalla 2016-04-07 a las 15.09.45
If you look well it is pretty simple. The find_threes function has 2 values inside, repeat and number[] (This will use an

Continue reading “Quiz 5”

Palindroming all day long

#TC1017 #QUIZ5

So this was hard. This, I must say, is one of my least effective codes written so far, it´s too long, buuuuuuut it works, so I´ll take it. Basically the user inputs the word, letter by letter (ineffective!) and then my code displays it the normal way and then reversed, just so the user sees it. Then it compares index by index to check if its the same.

The function .pushback was helpful for creating vectors of unknown size.

The real hard part was making it case unsensitive, oh man that took a while. Ken helped me out with a magical function and everything ran just fine. Also, mek sure to #include all necessary modules.

QUIZ5.PNG

Source Code below:[GitHub Link: https://github.com/diegodamy/Quiz5%5D

#include <iostream>
#include <vector>
#include <stdio.h>
#include <ctype.h>
using namespace std;

char DisplayWord (vector<char> word){ //Outputs word in order
int size = word.size();
vector<char>word1;

cout << “Your word: “;
for (int i = 0; i<word.size(); i++){
cout << word[i];
}
}

vector<char> DisplayWordReversed (vector<char> word){ //Outputs word in inverse order
int size = word.size();
vector<char>word2;
cout << endl << “Reversed: “;

for (int i = word.size()-1; i >=0; i–){
cout << word[i];
word2.push_back(word[i]);
}
return word2; //Returns value od reversed word (vector)
}

char FindPalindrome (vector<char> word, vector<char> word2){ //Compares indices of tow vectors: normal word and inversed word
int size = word.size();
cout << endl;
for (int i = 0; i<word.size(); i++){
if (word[i] == word2[i]){
return 1; //If elements of indices match, return true for palindrome
} else{
return 0;
}
}
}

int ConvertLowerUpper (){
int i=0;
char str[]=”Test String.n”;
char c;
while (str[i])
{
c=str[i];
putchar (tolower(c));
i++;
}
return 0;
}
int main(){
char letter;

cout << “Please enter letter by

Continue reading “Palindroming all day long”